Skip to content

Commit 2063967

Browse files
authored
Pin analyzers that ship in the SDK (#36690) (#36747)
* Pin analyzers that ship in the SDK ASP.NET Core produces a few analyzer assemblies that are shipped as part of the .NET SDK. These analyzers are added to web projects targeting 3.1 and newer. In 6.0, we (unintentionally) bumped the version of Microsoft.CodeAnalysis that these projects referenced to a 4.0 version. This causes warnings when opening a 3.1 or 5.0 app in VS 2019 as it does not support these versions. Additionally update the version of Microsoft.CodeAnalysis.* packages used in tests, Razor, and framework analyzers that are only expected to run with VS 2020 to a more recent build. This is largely book-keeping, but allows us to write a test for file scoped namespaces. Fixes #36552
1 parent fd0c956 commit 2063967

File tree

6 files changed

+21
-7
lines changed

6 files changed

+21
-7
lines changed

eng/Versions.props

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,16 @@
183183
<MicrosoftBuildUtilitiesCoreVersion>16.9.0</MicrosoftBuildUtilitiesCoreVersion>
184184
<MicrosoftBuildLocatorVersion>1.2.6</MicrosoftBuildLocatorVersion>
185185
<MicrosoftBuildUtilitiesCoreVersion>16.9.0</MicrosoftBuildUtilitiesCoreVersion>
186-
<MicrosoftCodeAnalysisCommonVersion>4.0.0-2.21354.7</MicrosoftCodeAnalysisCommonVersion>
187-
<MicrosoftCodeAnalysisCSharpVersion>4.0.0-2.21354.7</MicrosoftCodeAnalysisCSharpVersion>
188-
<MicrosoftCodeAnalysisCSharpWorkspacesVersion>4.0.0-2.21354.7</MicrosoftCodeAnalysisCSharpWorkspacesVersion>
186+
<!--
187+
Versions of Microsoft.CodeAnalysis packages referenced by analyzers shipped in the SDK.
188+
This need to be pinned since they're used in 3.1 apps and need to be loadable in VS 2019.
189+
-->
190+
<Analyzer_MicrosoftCodeAnalysisCSharpVersion>3.3.1</Analyzer_MicrosoftCodeAnalysisCSharpVersion>
191+
<Analyzer_MicrosoftCodeAnalysisCSharpWorkspacesVersion>3.3.1</Analyzer_MicrosoftCodeAnalysisCSharpWorkspacesVersion>
192+
193+
<MicrosoftCodeAnalysisCommonVersion>4.0.0-4.final</MicrosoftCodeAnalysisCommonVersion>
194+
<MicrosoftCodeAnalysisCSharpVersion>4.0.0-4.final</MicrosoftCodeAnalysisCSharpVersion>
195+
<MicrosoftCodeAnalysisCSharpWorkspacesVersion>4.0.0-4.final</MicrosoftCodeAnalysisCSharpWorkspacesVersion>
189196
<MicrosoftCodeAnalysisPublicApiAnalyzersVersion>3.3.0</MicrosoftCodeAnalysisPublicApiAnalyzersVersion>
190197
<MicrosoftCodeAnalysisCSharpCodeFixTestingXUnitVersion>1.1.1-beta1.21413.1</MicrosoftCodeAnalysisCSharpCodeFixTestingXUnitVersion>
191198
<MicrosoftCssParserVersion>1.0.0-20200708.1</MicrosoftCssParserVersion>

src/Analyzers/Analyzers/src/Microsoft.AspNetCore.Analyzers.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
</PropertyGroup>
1919

2020
<ItemGroup>
21-
<Reference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" PrivateAssets="All" />
21+
<!-- This analyzer is supported in VS 2019 and must use a compatible Microsoft.CodeAnalysis version -->
22+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="All" IsImplicitlyDefined="true" Version="$(Analyzer_MicrosoftCodeAnalysisCSharpVersion)" />
2223
</ItemGroup>
2324

2425
<ItemGroup>

src/Analyzers/Analyzers/test/MinimalStartupTest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public async Task StartupAnalyzer_WorksWithNonImplicitMain()
5353
using Microsoft.Extensions.DependencyInjection;
5454
using Microsoft.AspNetCore.Authorization;
5555
using Microsoft.AspNetCore.Mvc;
56+
57+
namespace MyApp;
58+
5659
public class Program
5760
{
5861
public static void Main(string[] args)

src/Components/Analyzers/src/Microsoft.AspNetCore.Components.Analyzers.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<Reference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" PrivateAssets="all" />
12+
<!-- This analyzer is supported in VS 2019 and must use a compatible Microsoft.CodeAnalysis version -->
13+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" PrivateAssets="All" IsImplicitlyDefined="true" Version="$(Analyzer_MicrosoftCodeAnalysisCSharpWorkspacesVersion)" />
1314
<PackageReference Update="NETStandard.Library" PrivateAssets="all" />
1415
</ItemGroup>
1516

src/Mvc/Mvc.Analyzers/src/Microsoft.AspNetCore.Mvc.Analyzers.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<Reference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" PrivateAssets="All" />
15+
<!-- This analyzer is supported in VS 2019 and must use a compatible Microsoft.CodeAnalysis version -->
16+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="All" IsImplicitlyDefined="true" Version="$(Analyzer_MicrosoftCodeAnalysisCSharpVersion)" />
1617
</ItemGroup>
1718

1819
<ItemGroup>

src/Mvc/Mvc.Api.Analyzers/src/Microsoft.AspNetCore.Mvc.Api.Analyzers.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
</ItemGroup>
1818

1919
<ItemGroup>
20-
<Reference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" PrivateAssets="All" />
20+
<!-- This analyzer is supported in VS 2019 and must use a compatible Microsoft.CodeAnalysis version -->
21+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" PrivateAssets="All" IsImplicitlyDefined="true" Version="$(Analyzer_MicrosoftCodeAnalysisCSharpWorkspacesVersion)" />
2122
</ItemGroup>
2223

2324
<ItemGroup>

0 commit comments

Comments
 (0)