Skip to content

Building a 5.0 app with 6.0 SDK in VS 2019 causes analyzers to fail to load #36552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pranavkm opened this issue Sep 15, 2021 · 7 comments · Fixed by #36690
Closed

Building a 5.0 app with 6.0 SDK in VS 2019 causes analyzers to fail to load #36552

pranavkm opened this issue Sep 15, 2021 · 7 comments · Fixed by #36690
Assignees
Labels
area-blazor Includes: Blazor, Razor Components area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates bug This issue describes a behavior which is not expected - a bug.
Milestone

Comments

@pranavkm
Copy link
Contributor

MVC and StartupAnalyzer are shipped as part of the SDK and target every version of .NET 3.1 onwards. These analyzers have been updated to reference Microsoft.CodeAnalysis versions 4.0.0.0 which isn't available on VS 2019. Consequently opening a 5.0 project with a 6.0 SDK results in a bunch of warnings:

1>CSC : warning CS8032: An instance of analyzer Microsoft.AspNetCore.Analyzers.StartupAnalyzer cannot be created from C:\Program Files\dotnet\sdk\6.0.100-rc.2.21464.10\Sdks\Microsoft.NET.Sdk.Web\analyzers\cs\Microsoft.AspNetCore.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
1>CSC : warning CS8032: An instance of analyzer Microsoft.AspNetCore.Mvc.Analyzers.AttributesShouldNotBeAppliedToPageModelAnalyzer cannot be created from C:\Program Files\dotnet\sdk\6.0.100-rc.2.21464.10\Sdks\Microsoft.NET.Sdk.Web\analyzers\cs\Microsoft.AspNetCore.Mvc.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
1>CSC : warning CS8032: An instance of analyzer Microsoft.AspNetCore.Mvc.Analyzers.AvoidHtmlPartialAnalyzer cannot be created from C:\Program Files\dotnet\sdk\6.0.100-rc.2.21464.10\Sdks\Microsoft.NET.Sdk.Web\analyzers\cs\Microsoft.AspNetCore.Mvc.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
1>CSC : warning CS8032: An instance of analyzer Microsoft.AspNetCore.Mvc.Analyzers.TagHelpersInCodeBlocksAnalyzer cannot be created from C:\Program Files\dotnet\sdk\6.0.100-rc.2.21464.10\Sdks\Microsoft.NET.Sdk.Web\analyzers\cs\Microsoft.AspNetCore.Mvc.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
1>CSC : warning CS8032: An instance of analyzer Microsoft.AspNetCore.Mvc.Analyzers.TopLevelParameterNameAnalyzer cannot be created from C:\Program Files\dotnet\sdk\6.0.100-rc.2.21464.10\Sdks\Microsoft.NET.Sdk.Web\analyzers\cs\Microsoft.AspNetCore.Mvc.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
1>CSC : warning CS8032: An instance of analyzer Microsoft.AspNetCore.Components.Analyzers.ComponentParameterAnalyzer cannot be created from C:\Program Files\dotnet\sdk\6.0.100-rc.2.21464.10\Sdks\Microsoft.NET.Sdk.Web\analyzers\cs\Microsoft.AspNetCore.Components.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
1>CSC : warning CS8032: An instance of analyzer Microsoft.AspNetCore.Components.Analyzers.ComponentParameterUsageAnalyzer cannot be created from C:\Program Files\dotnet\sdk\6.0.100-rc.2.21464.10\Sdks\Microsoft.NET.Sdk.Web\analyzers\cs\Microsoft.AspNetCore.Components.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
1>CSC : warning CS8032: An instance of analyzer Microsoft.Extensions.Internal.ComponentInternalUsageDiagnosticAnalyzer cannot be created from C:\Program Files\dotnet\sdk\6.0.100-rc.2.21464.10\Sdks\Microsoft.NET.Sdk.Web\analyzers\cs\Microsoft.AspNetCore.Components.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
1>CSC : warning CS8032: An instance of analyzer Microsoft.AspNetCore.Analyzers.StartupAnalyzer cannot be created from C:\Program Files\dotnet\sdk\6.0.100-rc.2.21464.10\Sdks\Microsoft.NET.Sdk.Web\analyzers\cs\Microsoft.AspNetCore.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
1>CSC : warning CS8032: An instance of analyzer Microsoft.AspNetCore.Mvc.Analyzers.AttributesShouldNotBeAppliedToPageModelAnalyzer cannot be created from C:\Program Files\dotnet\sdk\6.0.100-rc.2.21464.10\Sdks\Microsoft.NET.Sdk.Web\analyzers\cs\Microsoft.AspNetCore.Mvc.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
1>CSC : warning CS8032: An instance of analyzer Microsoft.AspNetCore.Mvc.Analyzers.AvoidHtmlPartialAnalyzer cannot be created from C:\Program Files\dotnet\sdk\6.0.100-rc.2.21464.10\Sdks\Microsoft.NET.Sdk.Web\analyzers\cs\Microsoft.AspNetCore.Mvc.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
1>CSC : warning CS8032: An instance of analyzer Microsoft.AspNetCore.Mvc.Analyzers.TagHelpersInCodeBlocksAnalyzer cannot be created from C:\Program Files\dotnet\sdk\6.0.100-rc.2.21464.10\Sdks\Microsoft.NET.Sdk.Web\analyzers\cs\Microsoft.AspNetCore.Mvc.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
1>CSC : warning CS8032: An instance of analyzer Microsoft.AspNetCore.Mvc.Analyzers.TopLevelParameterNameAnalyzer cannot be created from C:\Program Files\dotnet\sdk\6.0.100-rc.2.21464.10\Sdks\Microsoft.NET.Sdk.Web\analyzers\cs\Microsoft.AspNetCore.Mvc.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
1>CSC : warning CS8032: An instance of analyzer Microsoft.AspNetCore.Components.Analyzers.ComponentParameterAnalyzer cannot be created from C:\Program Files\dotnet\sdk\6.0.100-rc.2.21464.10\Sdks\Microsoft.NET.Sdk.Web\analyzers\cs\Microsoft.AspNetCore.Components.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
1>CSC : warning CS8032: An instance of analyzer Microsoft.AspNetCore.Components.Analyzers.ComponentParameterUsageAnalyzer cannot be created from C:\Program Files\dotnet\sdk\6.0.100-rc.2.21464.10\Sdks\Microsoft.NET.Sdk.Web\analyzers\cs\Microsoft.AspNetCore.Components.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
1>CSC : warning CS8032: An instance of analyzer Microsoft.Extensions.Internal.ComponentInternalUsageDiagnosticAnalyzer cannot be created from C:\Program Files\dotnet\sdk\6.0.100-rc.2.21464.10\Sdks\Microsoft.NET.Sdk.Web\analyzers\cs\Microsoft.AspNetCore.Components.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..

We should pin these to the the most recent version supported by VS2019.

@pranavkm pranavkm added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates bug This issue describes a behavior which is not expected - a bug. area-blazor Includes: Blazor, Razor Components labels Sep 15, 2021
@martincostello
Copy link
Member

Something similar to this case up when I raised a PR to file the logging source generator (dotnet/runtime#57894 (comment)) because it was using the old version, which made the type needed to understand file-scoped namespaces unavailable. I believe the folks over in runtime are/were looking into a multi-targeting solution to make both versions of VS happy.

@christiansparre
Copy link

This took me a bit to track down 😒

We have TreatWarningsAsErrors enabled so had to add NoWarn CS8032 to be able to build the solution in VS after installing rc1 yesterday...

@pranavkm pranavkm added this to the 6.0.0 milestone Sep 16, 2021
@pranavkm pranavkm self-assigned this Sep 16, 2021
pranavkm added a commit that referenced this issue Sep 17, 2021
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
pranavkm added a commit that referenced this issue Sep 18, 2021
* 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
pranavkm added a commit that referenced this issue Sep 20, 2021
* 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
pranavkm added a commit that referenced this issue Sep 20, 2021
* 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
dougbu pushed a commit that referenced this issue Sep 20, 2021
* 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
dougbu pushed a commit that referenced this issue Sep 20, 2021
* Pin analyzers that ship in the SDK (#36690)

* 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

* Apply suggestions from code review
@GearTheWorld
Copy link

Hi,

Is there a solution right now or we have to wait?

@pranavkm
Copy link
Contributor Author

You can prevent these analyzers from being added by configuring this MSBuild property:

<PropertyGroup>
   <DisableImplicitAspNetCoreAnalyzers>true</DisableImplicitAspNetCoreAnalyzers>
</PropertyGroup>

@GearTheWorld
Copy link

Where do you put that code?

@pranavkm
Copy link
Contributor Author

@GearTheWorld this would go in the project file (.csproj) that you're seeing this error in.

@GearTheWorld
Copy link

Great it works, thanx!

dougbu added a commit that referenced this issue Sep 22, 2021
* [release/6.0-rc2] Update dependencies from dotnet/efcore (#36635)

[release/6.0-rc2] Update dependencies from dotnet/efcore

* [release/6.0-rc2] Handle JsonExceptions in RequestDelegateFactory (#36627)

* Handle JsonExceptions like InvalidDataExceptions in RequestDelegateFactory

* Don't catch InvalidDataExceptions when reading JSON

* [release/6.0-rc2] Update dependencies from dotnet/runtime dotnet/efcore (#36651)

[release/6.0-rc2] Update dependencies from dotnet/runtime dotnet/efcore

* Avoid using invalid content type for ValidationProblemDetails (#36618)

Co-authored-by: Safia Abdalla <[email protected]>

* Update dependencies from https://github.com/dotnet/efcore build 20210917.6 (#36667)

[release/6.0-rc2] Update dependencies from dotnet/efcore

* Use a fake clock in the test (#36626)

Co-authored-by: Chris R <[email protected]>

* Update dependencies from https://github.com/dotnet/runtime build 20210917.8 (#36675)

[release/6.0-rc2] Update dependencies from dotnet/runtime

* [release/6.0-rc2] Throw for invalid TryParse and BindAsync (#36662)

* Backport of #36628 to release/6.0-rc2
* Throw for invalid TryParse and BindAsync
* nit
* use TypeNameHelper
* nit

Co-authored-by: Brennan <[email protected]>

* Update dependencies from https://github.com/dotnet/efcore build 20210917.8 (#36681)

[release/6.0-rc2] Update dependencies from dotnet/efcore

* Revert Enforce WebSockets Transport for Blazor (#36656)

* Revert Enforce WebSockets Transport for Blazor (changes introduced in #34644)
* Updated Release JS Files

* [release/6.0-rc2] Update dependencies from dotnet/runtime dotnet/efcore (#36687)

[release/6.0-rc2] Update dependencies from dotnet/runtime dotnet/efcore

* Update dependencies from https://github.com/dotnet/runtime build 20210917.25 (#36699)

[release/6.0-rc2] Update dependencies from dotnet/runtime

* Update dependencies from https://github.com/dotnet/efcore build 20210917.18 (#36701)

[release/6.0-rc2] Update dependencies from dotnet/efcore

* [release/6.0-rc2] Update dependencies from dotnet/efcore dotnet/runtime (#36706)

[release/6.0-rc2] Update dependencies from dotnet/efcore dotnet/runtime

* [Release/6.0-rc2] Fix and test HttpSys delegation (#36698)

* Out of proc delegation tests
* Troubleshoot IsFeatureSupported
* Fix test
* Fix formatting
* Seperate tests
* Cleanup
* Fix SLN

* Update dependencies from https://github.com/dotnet/efcore build 20210918.7 (#36715)

[release/6.0-rc2] Update dependencies from dotnet/efcore

* Find inherited TryParse and BindAsync (#36694)

Co-authored-by: Brennan <[email protected]>

* [release/6.0-rc2] Use minimal APIs for F# project templates (#36660)

* [release/6.0-rc2] Retarget DOTNETHOME when installing x64 on ARM64 (#36695)

* Retarget DOTNETHOME when installing x64 on ARM64

* Make platform comparison case insenstive

* Address feedback

* Install x64 registry keys to different path on ARM64 machine

Co-authored-by: Eric StJohn <[email protected]>

* Pin analyzers that ship in the SDK (#36690) (#36754)

* Pin analyzers that ship in the SDK (#36690)

* 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

* Apply suggestions from code review

* [release/6.0-rc2] Rename and consolidate  "DelegateEndpoint" types (#36578)

* Call AddEndpointsApiExplorer() in controllers Web API template (#36753)

- backport of #36752 to release/6.0-rc2

Co-authored-by: DamianEdwards <[email protected]>

* [release/6.0-rc2] Update dependencies from dotnet/efcore dotnet/runtime (#36769)

[release/6.0-rc2] Update dependencies from dotnet/efcore dotnet/runtime

* Update dependencies from https://github.com/dotnet/efcore build 20210920.20 (#36778)

[release/6.0-rc2] Update dependencies from dotnet/efcore

Co-authored-by: dotnet-maestro[bot] <42748379+dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Stephen Halter <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Safia Abdalla <[email protected]>
Co-authored-by: Chris R <[email protected]>
Co-authored-by: Brennan <[email protected]>
Co-authored-by: Tanay Parikh <[email protected]>
Co-authored-by: Chris Ross <[email protected]>
Co-authored-by: Eric StJohn <[email protected]>
Co-authored-by: Pranav K <[email protected]>
Co-authored-by: DamianEdwards <[email protected]>
@ghost ghost locked as resolved and limited conversation to collaborators Nov 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates bug This issue describes a behavior which is not expected - a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants