提交 749ad035 编写于 作者: J Jared Parsons

User Roslyn analyzers in all projects

The build system used to allow projects to opt out of anaylzers by
setting the property `$(UseRoslynAnalyzers)` to false before importing
Settings.props. This meant it occured at the top of the file above all
other elements, including the main property group block.

This doesn't really have an equivalent approach in the new SDK. There
is no way to pass a property value from the project file to the
Directory.Build.props file as it's implicitly imported.

The correct approach in the new SDK would be to do the following:

1. Define `$(UseRoslynAnalyzers)` in main property group block
1. Use the Roslyn analyzers as a `<PackageReference>` declaration in the
`Imports.targets` file and have it condition on `$(UseRoslynAnalyzers)`
not being false.

Doing that is a pretty siginificant rework of our build though. As a
test I just disabled the analyzers everywhere and found we had a total
of three warnings. Decided to just fix those as it was very straight
forward to do.
上级 c781532a
<?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 DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<UseRoslynAnalyzers>false</UseRoslynAnalyzers>
</PropertyGroup>
<Import Project="..\..\..\..\build\Targets\SettingsSdk.props" />
<PropertyGroup>
<NonShipping>true</NonShipping>
......@@ -33,4 +30,4 @@
<PackageReference Include="System.Composition" Version="$(SystemCompositionVersion)" />
</ItemGroup>
<Import Project="..\..\..\..\build\Targets\Imports.targets" />
</Project>
\ No newline at end of file
</Project>
<?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 DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<UseRoslynAnalyzers>false</UseRoslynAnalyzers>
</PropertyGroup>
<Import Project="..\..\..\..\..\build\Targets\SettingsSdk.props" />
<ItemGroup Label="Project References">
<ProjectReference Include="..\..\..\..\..\src\Compilers\Core\Portable\CodeAnalysis.csproj" />
......@@ -56,4 +53,4 @@
</None>
</ItemGroup>
<Import Project="..\..\..\..\..\build\Targets\Imports.targets" />
</Project>
\ No newline at end of file
</Project>
<?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 DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<UseRoslynAnalyzers>false</UseRoslynAnalyzers>
</PropertyGroup>
<Import Project="..\..\..\..\build\Targets\SettingsSdk.props" />
<PropertyGroup>
<Platform Condition="'$(Platform)' == ''">AnyCPU</Platform>
......
......@@ -21,10 +21,10 @@ Sub Main()
WriteLine(""Hello, World!"")
End Sub
End Module")
document = Await Formatter.FormatAsync(document)
Dim text As SourceText = Await document.GetTextAsync()
document = Await Formatter.FormatAsync(document).ConfigureAwait(true)
Dim text As SourceText = Await document.GetTextAsync().ConfigureAwait(true)
Dim classifiedSpans As IEnumerable(Of ClassifiedSpan) = Await Classifier.GetClassifiedSpansAsync(document, TextSpan.FromBounds(0, text.Length))
Dim classifiedSpans As IEnumerable(Of ClassifiedSpan) = Await Classifier.GetClassifiedSpansAsync(document, TextSpan.FromBounds(0, text.Length)).ConfigureAwait(true)
Console.BackgroundColor = ConsoleColor.Black
Dim ranges = From span As ClassifiedSpan In classifiedSpans
......
<?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 DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<UseRoslynAnalyzers>false</UseRoslynAnalyzers>
</PropertyGroup>
<Import Project="..\..\..\..\..\build\Targets\SettingsSdk.props" />
<ItemGroup Label="Project References">
<ProjectReference Include="..\..\..\..\..\src\Compilers\Core\Portable\CodeAnalysis.csproj" />
......@@ -64,4 +61,4 @@
<InternalsVisibleToTest Include="MakeConstVB.UnitTests" />
</ItemGroup>
<Import Project="..\..\..\..\..\build\Targets\Imports.targets" />
</Project>
\ No newline at end of file
</Project>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册