Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
f0be63df
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,发现更多精彩内容 >>
未验证
提交
f0be63df
编写于
6月 05, 2019
作者:
J
Jason Malinowski
提交者:
GitHub
6月 05, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #35848 from jasonmalinowski/add-editorconfig-support-to-msbuildworkspace
Add support for .editorconfig files to MSBuildWorkspace
上级
cf6c2b98
338f4880
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
129 addition
and
6 deletion
+129
-6
src/Workspaces/Core/MSBuild/MSBuild/Constants/ItemNames.cs
src/Workspaces/Core/MSBuild/MSBuild/Constants/ItemNames.cs
+1
-0
src/Workspaces/Core/MSBuild/MSBuild/MSBuildProjectLoader.Worker.cs
...paces/Core/MSBuild/MSBuild/MSBuildProjectLoader.Worker.cs
+6
-4
src/Workspaces/Core/MSBuild/MSBuild/ProjectFile/Extensions.cs
...Workspaces/Core/MSBuild/MSBuild/ProjectFile/Extensions.cs
+3
-0
src/Workspaces/Core/MSBuild/MSBuild/ProjectFile/ProjectFile.cs
...orkspaces/Core/MSBuild/MSBuild/ProjectFile/ProjectFile.cs
+7
-2
src/Workspaces/Core/MSBuild/MSBuild/ProjectFile/ProjectFileInfo.cs
...paces/Core/MSBuild/MSBuild/ProjectFile/ProjectFileInfo.cs
+10
-0
src/Workspaces/MSBuildTest/MSBuildWorkspaceTests.cs
src/Workspaces/MSBuildTest/MSBuildWorkspaceTests.cs
+40
-0
src/Workspaces/MSBuildTest/Resources/ProjectFiles/CSharp/WithDiscoverEditorConfigFiles.csproj
.../ProjectFiles/CSharp/WithDiscoverEditorConfigFiles.csproj
+61
-0
src/Workspaces/MSBuildTest/TestFiles/Resources.cs
src/Workspaces/MSBuildTest/TestFiles/Resources.cs
+1
-0
未找到文件。
src/Workspaces/Core/MSBuild/MSBuild/Constants/ItemNames.cs
浏览文件 @
f0be63df
...
...
@@ -9,6 +9,7 @@ internal static class ItemNames
public
const
string
Compile
=
nameof
(
Compile
);
public
const
string
CscCommandLineArgs
=
nameof
(
CscCommandLineArgs
);
public
const
string
DocFileItem
=
nameof
(
DocFileItem
);
public
const
string
EditorConfigFiles
=
nameof
(
EditorConfigFiles
);
public
const
string
Import
=
nameof
(
Import
);
public
const
string
ProjectReference
=
nameof
(
ProjectReference
);
public
const
string
Reference
=
nameof
(
Reference
);
...
...
src/Workspaces/Core/MSBuild/MSBuild/MSBuildProjectLoader.Worker.cs
浏览文件 @
f0be63df
...
...
@@ -361,7 +361,8 @@ private Task<ProjectInfo> CreateProjectInfoAsync(ProjectFileInfo projectFileInfo
var
documents
=
CreateDocumentInfos
(
projectFileInfo
.
Documents
,
projectId
,
commandLineArgs
.
Encoding
);
var
additionalDocuments
=
CreateDocumentInfos
(
projectFileInfo
.
AdditionalDocuments
,
projectId
,
commandLineArgs
.
Encoding
);
CheckForDuplicateDocuments
(
documents
,
additionalDocuments
,
projectPath
,
projectId
);
var
analyzerConfigDocuments
=
CreateDocumentInfos
(
projectFileInfo
.
AnalyzerConfigDocuments
,
projectId
,
commandLineArgs
.
Encoding
);
CheckForDuplicateDocuments
(
documents
.
Concat
(
additionalDocuments
).
Concat
(
analyzerConfigDocuments
),
projectPath
,
projectId
);
var
analyzerReferences
=
ResolveAnalyzerReferences
(
commandLineArgs
);
...
...
@@ -385,7 +386,8 @@ private Task<ProjectInfo> CreateProjectInfoAsync(ProjectFileInfo projectFileInfo
additionalDocuments
:
additionalDocuments
,
isSubmission
:
false
,
hostObjectType
:
null
)
.
WithDefaultNamespace
(
projectFileInfo
.
DefaultNamespace
);
.
WithDefaultNamespace
(
projectFileInfo
.
DefaultNamespace
)
.
WithAnalyzerConfigDocuments
(
analyzerConfigDocuments
);
});
}
...
...
@@ -473,10 +475,10 @@ private static void GetDocumentNameAndFolders(string logicalPath, out string nam
}
}
private
void
CheckForDuplicateDocuments
(
ImmutableArray
<
DocumentInfo
>
documents
,
ImmutableArray
<
DocumentInfo
>
additionalDocuments
,
string
projectFilePath
,
ProjectId
projectId
)
private
void
CheckForDuplicateDocuments
(
ImmutableArray
<
DocumentInfo
>
documents
,
string
projectFilePath
,
ProjectId
projectId
)
{
var
paths
=
new
HashSet
<
string
>(
PathUtilities
.
Comparer
);
foreach
(
var
doc
in
documents
.
Concat
(
additionalDocuments
)
)
foreach
(
var
doc
in
documents
)
{
if
(
paths
.
Contains
(
doc
.
FilePath
))
{
...
...
src/Workspaces/Core/MSBuild/MSBuild/ProjectFile/Extensions.cs
浏览文件 @
f0be63df
...
...
@@ -20,6 +20,9 @@ public static IEnumerable<MSB.Framework.ITaskItem> GetAnalyzers(this MSB.Executi
public
static
IEnumerable
<
MSB
.
Framework
.
ITaskItem
>
GetDocuments
(
this
MSB
.
Execution
.
ProjectInstance
executedProject
)
=>
executedProject
.
GetItems
(
ItemNames
.
Compile
);
public
static
IEnumerable
<
MSB
.
Framework
.
ITaskItem
>
GetEditorConfigFiles
(
this
MSB
.
Execution
.
ProjectInstance
executedProject
)
=>
executedProject
.
GetItems
(
ItemNames
.
EditorConfigFiles
);
public
static
IEnumerable
<
MSB
.
Framework
.
ITaskItem
>
GetMetadataReferences
(
this
MSB
.
Execution
.
ProjectInstance
executedProject
)
=>
executedProject
.
GetItems
(
ItemNames
.
ReferencePath
);
...
...
src/Workspaces/Core/MSBuild/MSBuild/ProjectFile/ProjectFile.cs
浏览文件 @
f0be63df
...
...
@@ -138,7 +138,11 @@ private ProjectFileInfo CreateProjectFileInfo(MSB.Execution.ProjectInstance proj
.
ToImmutableArray
();
var
additionalDocs
=
project
.
GetAdditionalFiles
()
.
Select
(
MakeAdditionalDocumentFileInfo
)
.
Select
(
MakeNonSourceFileDocumentFileInfo
)
.
ToImmutableArray
();
var
analyzerConfigDocs
=
project
.
GetEditorConfigFiles
()
.
Select
(
MakeNonSourceFileDocumentFileInfo
)
.
ToImmutableArray
();
return
ProjectFileInfo
.
Create
(
...
...
@@ -151,6 +155,7 @@ private ProjectFileInfo CreateProjectFileInfo(MSB.Execution.ProjectInstance proj
commandLineArgs
,
docs
,
additionalDocs
,
analyzerConfigDocs
,
project
.
GetProjectReferences
().
ToImmutableArray
(),
Log
);
}
...
...
@@ -187,7 +192,7 @@ private DocumentFileInfo MakeDocumentFileInfo(MSB.Framework.ITaskItem documentIt
return
new
DocumentFileInfo
(
filePath
,
logicalPath
,
isLinked
,
isGenerated
,
sourceCodeKind
);
}
private
DocumentFileInfo
Make
Additional
DocumentFileInfo
(
MSB
.
Framework
.
ITaskItem
documentItem
)
private
DocumentFileInfo
Make
NonSourceFile
DocumentFileInfo
(
MSB
.
Framework
.
ITaskItem
documentItem
)
{
var
filePath
=
GetDocumentFilePath
(
documentItem
);
var
logicalPath
=
GetDocumentLogicalPath
(
documentItem
,
_projectDirectory
);
...
...
src/Workspaces/Core/MSBuild/MSBuild/ProjectFile/ProjectFileInfo.cs
浏览文件 @
f0be63df
...
...
@@ -69,6 +69,11 @@ internal sealed class ProjectFileInfo
/// </summary>
public
ImmutableArray
<
DocumentFileInfo
>
AdditionalDocuments
{
get
;
}
/// <summary>
/// The analyzer config documents.
/// </summary>
public
ImmutableArray
<
DocumentFileInfo
>
AnalyzerConfigDocuments
{
get
;
}
/// <summary>
/// References to other projects.
/// </summary>
...
...
@@ -96,6 +101,7 @@ public override string ToString()
ImmutableArray
<
string
>
commandLineArgs
,
ImmutableArray
<
DocumentFileInfo
>
documents
,
ImmutableArray
<
DocumentFileInfo
>
additionalDocuments
,
ImmutableArray
<
DocumentFileInfo
>
analyzerConfigDocuments
,
ImmutableArray
<
ProjectFileReference
>
projectReferences
,
DiagnosticLog
log
)
{
...
...
@@ -111,6 +117,7 @@ public override string ToString()
this
.
CommandLineArgs
=
commandLineArgs
;
this
.
Documents
=
documents
;
this
.
AdditionalDocuments
=
additionalDocuments
;
this
.
AnalyzerConfigDocuments
=
analyzerConfigDocuments
;
this
.
ProjectReferences
=
projectReferences
;
this
.
Log
=
log
;
}
...
...
@@ -125,6 +132,7 @@ public override string ToString()
ImmutableArray
<
string
>
commandLineArgs
,
ImmutableArray
<
DocumentFileInfo
>
documents
,
ImmutableArray
<
DocumentFileInfo
>
additionalDocuments
,
ImmutableArray
<
DocumentFileInfo
>
analyzerConfigDocuments
,
ImmutableArray
<
ProjectFileReference
>
projectReferences
,
DiagnosticLog
log
)
=>
new
ProjectFileInfo
(
...
...
@@ -138,6 +146,7 @@ public override string ToString()
commandLineArgs
,
documents
,
additionalDocuments
,
analyzerConfigDocuments
,
projectReferences
,
log
);
...
...
@@ -153,6 +162,7 @@ public static ProjectFileInfo CreateEmpty(string language, string filePath, Diag
commandLineArgs
:
ImmutableArray
<
string
>.
Empty
,
documents
:
ImmutableArray
<
DocumentFileInfo
>.
Empty
,
additionalDocuments
:
ImmutableArray
<
DocumentFileInfo
>.
Empty
,
analyzerConfigDocuments
:
ImmutableArray
<
DocumentFileInfo
>.
Empty
,
projectReferences
:
ImmutableArray
<
ProjectFileReference
>.
Empty
,
log
);
}
...
...
src/Workspaces/MSBuildTest/MSBuildWorkspaceTests.cs
浏览文件 @
f0be63df
...
...
@@ -3628,6 +3628,46 @@ public async Task TestDuplicateProjectReference()
}
}
[
ConditionalFact
(
typeof
(
VisualStudioMSBuildInstalled
),
AlwaysSkip
=
"https://github.com/dotnet/core-eng/issues/6424"
),
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
MSBuildWorkspace
)]
public
async
Task
TestEditorConfigDiscovery
()
{
var
files
=
GetSimpleCSharpSolutionFiles
()
.
WithFile
(
@"CSharpProject\CSharpProject.csproj"
,
Resources
.
ProjectFiles
.
CSharp
.
WithDiscoverEditorConfigFiles
)
.
WithFile
(
".editorconfig"
,
"root = true"
);
CreateFiles
(
files
);
using
(
var
workspace
=
CreateMSBuildWorkspace
())
{
var
projectFullPath
=
GetSolutionFileName
(
@"CSharpProject\CSharpProject.csproj"
);
var
project
=
await
workspace
.
OpenProjectAsync
(
projectFullPath
);
var
analyzerConfigDocument
=
Assert
.
Single
(
project
.
AnalyzerConfigDocuments
);
Assert
.
Equal
(
".editorconfig"
,
analyzerConfigDocument
.
Name
);
var
text
=
await
analyzerConfigDocument
.
GetTextAsync
();
Assert
.
Equal
(
"root = true"
,
text
.
ToString
());
}
}
[
ConditionalFact
(
typeof
(
VisualStudioMSBuildInstalled
)),
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
MSBuildWorkspace
)]
public
async
Task
TestEditorConfigDiscoveryDisabled
()
{
var
files
=
GetSimpleCSharpSolutionFiles
()
.
WithFile
(
@"CSharpProject\CSharpProject.csproj"
,
Resources
.
ProjectFiles
.
CSharp
.
WithDiscoverEditorConfigFiles
)
.
ReplaceFileElement
(
@"CSharpProject\CSharpProject.csproj"
,
"DiscoverEditorConfigFiles"
,
"false"
)
.
WithFile
(
".editorconfig"
,
"root = true"
);
CreateFiles
(
files
);
using
(
var
workspace
=
CreateMSBuildWorkspace
())
{
var
projectFullPath
=
GetSolutionFileName
(
@"CSharpProject\CSharpProject.csproj"
);
var
project
=
await
workspace
.
OpenProjectAsync
(
projectFullPath
);
Assert
.
Empty
(
project
.
AnalyzerConfigDocuments
);
}
}
private
class
InMemoryAssemblyLoader
:
IAnalyzerAssemblyLoader
{
public
void
AddDependencyLocation
(
string
fullPath
)
...
...
src/Workspaces/MSBuildTest/Resources/ProjectFiles/CSharp/WithDiscoverEditorConfigFiles.csproj
0 → 100644
浏览文件 @
f0be63df
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -->
<Project
ToolsVersion=
"4.0"
DefaultTargets=
"Build"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<Import
Project=
"$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"
Condition=
"Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"
/>
<PropertyGroup>
<Configuration
Condition=
"'$(Configuration)' == ''"
>
Debug
</Configuration>
<Platform
Condition=
"'$(Platform)' == ''"
>
AnyCPU
</Platform>
<PlatformTarget>
AnyCPU
</PlatformTarget>
<ProjectGuid>
{9705A8E6-C854-4FD3-8CEA-EDBDD54C7FD8}
</ProjectGuid>
<OutputType>
Exe
</OutputType>
<AppDesignerFolder>
Properties
</AppDesignerFolder>
<RootNamespace>
ConsoleApplication62
</RootNamespace>
<AssemblyName>
ConsoleApplication62
</AssemblyName>
<TargetFrameworkVersion>
v4.5
</TargetFrameworkVersion>
<FileAlignment>
512
</FileAlignment>
<DiscoverEditorConfigFiles>
true
</DiscoverEditorConfigFiles>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'"
>
<PlatformTarget>
AnyCPU
</PlatformTarget>
<DebugSymbols>
true
</DebugSymbols>
<DebugType>
full
</DebugType>
<Optimize>
false
</Optimize>
<OutputPath>
bin\Debug\
</OutputPath>
<DefineConstants>
DEBUG;TRACE
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)' == 'Release|AnyCPU'"
>
<PlatformTarget>
AnyCPU
</PlatformTarget>
<DebugType>
pdbonly
</DebugType>
<Optimize>
true
</Optimize>
<OutputPath>
bin\Release\
</OutputPath>
<DefineConstants>
TRACE
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference
Include=
"Microsoft.CSharp"
/>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Core"
/>
<Reference
Include=
"System.Data"
/>
<Reference
Include=
"System.Data.DataSetExtensions"
/>
<Reference
Include=
"System.Xml"
/>
<Reference
Include=
"System.Xml.Linq"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"CSharpClass.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
</ItemGroup>
<ItemGroup>
<None
Include=
"app.config"
/>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
src/Workspaces/MSBuildTest/TestFiles/Resources.cs
浏览文件 @
f0be63df
...
...
@@ -149,6 +149,7 @@ public static class CSharp
public
static
string
ReferencesPortableProject
=>
GetText
(
"ProjectFiles.CSharp.ReferencesPortableProject.csproj"
);
public
static
string
Wildcards
=>
GetText
(
"ProjectFiles.CSharp.Wildcards.csproj"
);
public
static
string
WithoutCSharpTargetsImported
=>
GetText
(
"ProjectFiles.CSharp.WithoutCSharpTargetsImported.csproj"
);
public
static
string
WithDiscoverEditorConfigFiles
=>
GetText
(
"ProjectFiles.CSharp.WithDiscoverEditorConfigFiles.csproj"
);
public
static
string
WithPrefer32Bit
=>
GetText
(
"ProjectFiles.CSharp.WithPrefer32Bit.csproj"
);
public
static
string
WithLink
=>
GetText
(
"ProjectFiles.CSharp.WithLink.csproj"
);
public
static
string
WithSystemNumerics
=>
GetText
(
"ProjectFiles.CSharp.WithSystemNumerics.csproj"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录