andrewabest/Conventional

Running built-in Roslyn analyzer fails build in Visual Studio 2022

Closed this issue · 0 comments

image
Got

AD0001 Analyzer 'Conventional.Roslyn.Analyzers.IfAndElseMustHaveBracesAnalyzer' threw an exception of type 'System.IO.FileNotFoundException' with message 'Could not load file or assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.'.

'Conventional.Roslyn.Analyzers.UsingsStatementsMustNotBeNestedAnalyzer' threw an exception of type 'System.IO.FileNotFoundException' with message 'Could not load file or assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.'.

in latest visual studio 2022 Version 17.7.6 (but works fine in Rider)

Workaround:
Configure project to stop using analyzers in live mode or on build
image
image

Question to owner:

Perhaps its time to upgrade from dotnet standard to .net 6 as well @andrewabest, or multi target to all LTS versions atm, including .netStandard2.1?

Reasoning: to be able to run those analysers in life analysis mode or on build those analysers dll must target the same target framework as the project that is pulling the nuget package.

I can make that change if you are OK with this proposed solution...

https://github.com/andrewabest/Conventional/blob/14c7302594621c3b1b628067612a7f4ec16a3857/src/Roslyn/Conventional.Roslyn.Analyzers/Conventional.Roslyn.Analyzers.csproj#L4C6-L4C6

  <PropertyGroup>
        <TargetFrameworks>netstandard2.1;net6.0;net7.0</TargetFrameworks>
        <EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
    </PropertyGroup>

for both Roslyn and Analyzers projects.