Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
e2ce8630
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
e2ce8630
编写于
11月 11, 2019
作者:
S
Sam Harwell
提交者:
GitHub
11月 11, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #39748 from ltrzesniewski/fix-39724
Use global properties to iterate over TFMs in MSBuildWorkspace
上级
40f4f254
32157875
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
103 addition
and
8 deletion
+103
-8
src/Workspaces/Core/MSBuild/MSBuild/ProjectFile/ProjectFile.cs
...orkspaces/Core/MSBuild/MSBuild/ProjectFile/ProjectFile.cs
+7
-8
src/Workspaces/MSBuildTest/NetCoreTests.cs
src/Workspaces/MSBuildTest/NetCoreTests.cs
+68
-0
src/Workspaces/MSBuildTest/Resources/NetCoreMultiTFM_ExtensionWithConditionOnTFM/Project.csproj
...etCoreMultiTFM_ExtensionWithConditionOnTFM/Project.csproj
+7
-0
src/Workspaces/MSBuildTest/Resources/NetCoreMultiTFM_ExtensionWithConditionOnTFM/Project.csproj.test.props
...TFM_ExtensionWithConditionOnTFM/Project.csproj.test.props
+9
-0
src/Workspaces/MSBuildTest/TestFiles/Resources.cs
src/Workspaces/MSBuildTest/TestFiles/Resources.cs
+2
-0
src/Workspaces/MSBuildTest/WorkspaceTestBase.cs
src/Workspaces/MSBuildTest/WorkspaceTestBase.cs
+10
-0
未找到文件。
src/Workspaces/Core/MSBuild/MSBuild/ProjectFile/ProjectFile.cs
浏览文件 @
e2ce8630
...
...
@@ -56,13 +56,15 @@ public async Task<ImmutableArray<ProjectFileInfo>> GetProjectFileInfosAsync(Canc
// In this case, we need to iterate through the <TargetFrameworks>, set <TargetFramework> with
// each value, and build the project.
var
hasTargetFrameworkProp
=
_loadedProject
.
GetProperty
(
PropertyNames
.
TargetFramework
)
!=
null
;
var
targetFrameworks
=
targetFrameworksValue
.
Split
(
';'
);
var
results
=
ImmutableArray
.
CreateBuilder
<
ProjectFileInfo
>(
targetFrameworks
.
Length
);
if
(!
_loadedProject
.
GlobalProperties
.
TryGetValue
(
PropertyNames
.
TargetFramework
,
out
var
initialGlobalTargetFrameworkValue
))
initialGlobalTargetFrameworkValue
=
null
;
foreach
(
var
targetFramework
in
targetFrameworks
)
{
_loadedProject
.
SetProperty
(
PropertyNames
.
TargetFramework
,
targetFramework
);
_loadedProject
.
Set
Global
Property
(
PropertyNames
.
TargetFramework
,
targetFramework
);
_loadedProject
.
ReevaluateIfNecessary
();
var
projectFileInfo
=
await
BuildProjectFileInfoAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
...
...
@@ -70,16 +72,13 @@ public async Task<ImmutableArray<ProjectFileInfo>> GetProjectFileInfosAsync(Canc
results
.
Add
(
projectFileInfo
);
}
// Remove the <TargetFramework> property if it didn't exist in the file before we set it.
// Otherwise, set it back to it's original value.
if
(!
hasTargetFrameworkProp
)
if
(
initialGlobalTargetFrameworkValue
is
null
)
{
var
targetFrameworkProp
=
_loadedProject
.
GetProperty
(
PropertyNames
.
TargetFramework
);
_loadedProject
.
RemoveProperty
(
targetFrameworkProp
);
_loadedProject
.
RemoveGlobalProperty
(
PropertyNames
.
TargetFramework
);
}
else
{
_loadedProject
.
Set
Property
(
PropertyNames
.
TargetFramework
,
t
argetFrameworkValue
);
_loadedProject
.
Set
GlobalProperty
(
PropertyNames
.
TargetFramework
,
initialGlobalT
argetFrameworkValue
);
}
_loadedProject
.
ReevaluateIfNecessary
();
...
...
src/Workspaces/MSBuildTest/NetCoreTests.cs
浏览文件 @
e2ce8630
...
...
@@ -213,6 +213,50 @@ public async Task TestOpenProject_NetCoreMultiTFM()
}
}
[
ConditionalFact
(
typeof
(
VisualStudioMSBuildInstalled
),
typeof
(
DotNetCoreSdk
.
IsAvailable
))]
[
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
MSBuildWorkspace
)]
[
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
NetCore
)]
public
async
Task
TestOpenProject_NetCoreMultiTFM_ExtensionWithConditionOnTFM
()
{
CreateFiles
(
GetNetCoreMultiTFMFiles_ExtensionWithConditionOnTFM
());
var
projectFilePath
=
GetSolutionFileName
(
"Project.csproj"
);
DotNetRestore
(
"Project.csproj"
);
using
(
var
workspace
=
CreateMSBuildWorkspace
())
{
await
workspace
.
OpenProjectAsync
(
projectFilePath
);
// Assert that three projects have been loaded, one for each TFM.
Assert
.
Equal
(
3
,
workspace
.
CurrentSolution
.
ProjectIds
.
Count
);
// Assert the TFM is accessible from project extensions.
// The test project extension sets the default namespace based on the TFM.
foreach
(
var
project
in
workspace
.
CurrentSolution
.
Projects
)
{
switch
(
project
.
Name
)
{
case
"Project(netcoreapp2.1)"
:
Assert
.
Equal
(
"Project.NetCore"
,
project
.
DefaultNamespace
);
break
;
case
"Project(netstandard2.0)"
:
Assert
.
Equal
(
"Project.NetStandard"
,
project
.
DefaultNamespace
);
break
;
case
"Project(net461)"
:
Assert
.
Equal
(
"Project.NetFramework"
,
project
.
DefaultNamespace
);
break
;
default
:
Assert
.
True
(
false
,
$"Unexpected project:
{
project
.
Name
}
"
);
break
;
}
}
}
}
[
ConditionalFact
(
typeof
(
VisualStudioMSBuildInstalled
),
typeof
(
DotNetCoreSdk
.
IsAvailable
))]
[
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
MSBuildWorkspace
)]
[
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
NetCore
)]
...
...
@@ -395,5 +439,29 @@ public async Task TestOpenProject_ReferenceConfigurationSpecificMetadata()
var
compilation
=
await
project
.
GetCompilationAsync
();
}
}
[
ConditionalFact
(
typeof
(
VisualStudioMSBuildInstalled
),
typeof
(
DotNetCoreSdk
.
IsAvailable
))]
[
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
MSBuildWorkspace
)]
[
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
NetCore
)]
public
async
Task
TestOpenProject_OverrideTFM
()
{
CreateFiles
(
GetNetCoreApp2AndLibraryFiles
());
var
projectFilePath
=
GetSolutionFileName
(
@"Library\Library.csproj"
);
DotNetRestore
(
@"Library\Library.csproj"
);
// Override the TFM properties defined in the file
using
(
var
workspace
=
CreateMSBuildWorkspace
((
PropertyNames
.
TargetFramework
,
""
),
(
PropertyNames
.
TargetFrameworks
,
"netcoreapp2.1;net461"
)))
{
await
workspace
.
OpenProjectAsync
(
projectFilePath
);
// Assert that two projects have been loaded, one for each TFM.
Assert
.
Equal
(
2
,
workspace
.
CurrentSolution
.
ProjectIds
.
Count
);
Assert
.
Contains
(
workspace
.
CurrentSolution
.
Projects
,
p
=>
p
.
Name
==
"Library(netcoreapp2.1)"
);
Assert
.
Contains
(
workspace
.
CurrentSolution
.
Projects
,
p
=>
p
.
Name
==
"Library(net461)"
);
}
}
}
}
src/Workspaces/MSBuildTest/Resources/NetCoreMultiTFM_ExtensionWithConditionOnTFM/Project.csproj
0 → 100644
浏览文件 @
e2ce8630
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;netstandard2.0;net461</TargetFrameworks>
</PropertyGroup>
</Project>
src/Workspaces/MSBuildTest/Resources/NetCoreMultiTFM_ExtensionWithConditionOnTFM/Project.csproj.test.props
0 → 100644
浏览文件 @
e2ce8630
<Project>
<PropertyGroup>
<RootNamespace Condition="'$(TargetFramework)' == 'netcoreapp2.1'">Project.NetCore</RootNamespace>
<RootNamespace Condition="'$(TargetFramework)' == 'netstandard2.0'">Project.NetStandard</RootNamespace>
<RootNamespace Condition="'$(TargetFramework)' == 'net461'">Project.NetFramework</RootNamespace>
</PropertyGroup>
</Project>
src/Workspaces/MSBuildTest/TestFiles/Resources.cs
浏览文件 @
e2ce8630
...
...
@@ -138,6 +138,8 @@ public static class CSharp
public
static
string
NetCoreApp2AndTwoLibraries_Library1
=>
GetText
(
"NetCoreApp2AndTwoLibraries.Library1.csproj"
);
public
static
string
NetCoreApp2AndTwoLibraries_Library2
=>
GetText
(
"NetCoreApp2AndTwoLibraries.Library2.csproj"
);
public
static
string
NetCoreMultiTFM_Project
=>
GetText
(
"NetCoreMultiTFM.Project.csproj"
);
public
static
string
NetCoreMultiTFM_ExtensionWithConditionOnTFM_Project
=>
GetText
(
"NetCoreMultiTFM_ExtensionWithConditionOnTFM.Project.csproj"
);
public
static
string
NetCoreMultiTFM_ExtensionWithConditionOnTFM_ProjectTestProps
=>
GetText
(
"NetCoreMultiTFM_ExtensionWithConditionOnTFM.Project.csproj.test.props"
);
public
static
string
NetCoreMultiTFM_ProjectReference_Library
=>
GetText
(
"NetCoreMultiTFM_ProjectReference.Library.csproj"
);
public
static
string
NetCoreMultiTFM_ProjectReference_Project
=>
GetText
(
"NetCoreMultiTFM_ProjectReference.Project.csproj"
);
public
static
string
NetCoreMultiTFM_ProjectReferenceToFSharp_CSharpLib
=
GetText
(
"NetCoreMultiTFM_ProjectReferenceToFSharp.csharplib.csharplib.csproj"
);
...
...
src/Workspaces/MSBuildTest/WorkspaceTestBase.cs
浏览文件 @
e2ce8630
...
...
@@ -153,6 +153,16 @@ protected FileSet GetNetCoreMultiTFMFiles()
(
@"Program.cs"
,
Resources
.
SourceFiles
.
CSharp
.
NetCoreApp2_Program
));
}
protected
FileSet
GetNetCoreMultiTFMFiles_ExtensionWithConditionOnTFM
()
{
return
new
FileSet
(
(
@"NuGet.Config"
,
Resources
.
NuGet_Config
),
(
@"Directory.Build.props"
,
Resources
.
Directory_Build_props
),
(
@"Directory.Build.targets"
,
Resources
.
Directory_Build_targets
),
(
@"Project.csproj"
,
Resources
.
ProjectFiles
.
CSharp
.
NetCoreMultiTFM_ExtensionWithConditionOnTFM_Project
),
(
@"obj\Project.csproj.test.props"
,
Resources
.
ProjectFiles
.
CSharp
.
NetCoreMultiTFM_ExtensionWithConditionOnTFM_ProjectTestProps
));
}
protected
FileSet
GetNetCoreMultiTFMFiles_ProjectReference
()
{
return
new
FileSet
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录