Roslyn-analyzers: VSTS build fails after updating to 2.6.0

Created on 18 Jan 2018  路  10Comments  路  Source: dotnet/roslyn-analyzers

Analyzer package

Example: Microsoft.CodeQuality.Analyzers, version 2.6.0(https://www.nuget.org/packages/Microsoft.CodeQuality.Analyzers/2.6.0)

Analyzer

Updated nuget from 1.1.0 to 2.6.0 in a C# .NET Framework 4.6.1 class library project.

VSTS builds now fail with the following errors.

Repro steps

  1. Create C# .NET Framework 4.6.1 assembly with Microsoft.AspNetCore.Mvc 2.0.0 nuget. (which will indirectly include Razor and then Code Analysis).
  2. Create VSTS build
  3. Attempt build... fails.

These are the full set of packages in my assembly.



































































































































Expected behavior

Clean build

Actual behavior

CSC (0, 0)
CSC(0,0): Error CS8032: An instance of analyzer Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.DiagnosticAnalyzerAttributeAnalyzer cannot be created from d:\a\1\s\packages\Microsoft.CodeAnalysis.Analyzers.2.6.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=2.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
CSC (0, 0)
CSC(0,0): Error CS8032: An instance of analyzer Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.DiagnosticDescriptorCreationAnalyzer cannot be created from d:\a\1\s\packages\Microsoft.CodeAnalysis.Analyzers.2.6.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=2.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
CSC (0, 0)
CSC(0,0): Error CS8032: An instance of analyzer Microsoft.CodeAnalysis.Analyzers.FixAnalyzers.FixerWithFixAllAnalyzer cannot be created from d:\a\1\s\packages\Microsoft.CodeAnalysis.Analyzers.2.6.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=2.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
CSC (0, 0)
CSC(0,0): Error CS8032: An instance of analyzer Microsoft.CodeAnalysis.Analyzers.InternalImplementationOnlyAnalyzer cannot be created from d:\a\1\s\packages\Microsoft.CodeAnalysis.Analyzers.2.6.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=2.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
CSC (0, 0)
CSC(0,0): Error CS8032: An instance of analyzer Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpReportDiagnosticAnalyzer cannot be created from d:\a\1\s\packages\Microsoft.CodeAnalysis.Analyzers.2.6.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=2.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
CSC (0, 0)
CSC(0,0): Error CS8032: An instance of analyzer Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpDiagnosticAnalyzerFieldsAnalyzer cannot be created from d:\a\1\s\packages\Microsoft.CodeAnalysis.Analyzers.2.6.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=2.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
CSC (0, 0)
CSC(0,0): Error CS8032: An instance of analyzer Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpRegisterActionAnalyzer cannot be created from d:\a\1\s\packages\Microsoft.CodeAnalysis.Analyzers.2.6.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=2.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
CSC (0, 0)
CSC(0,0): Error CS8032: An instance of analyzer Microsoft.CodeAnalysis.CSharp.Analyzers.CSharpImmutableObjectMethodAnalyzer cannot be created from d:\a\1\s\packages\Microsoft.CodeAnalysis.Analyzers.2.6.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=2.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..

Bug

Most helpful comment

@mavasani Adding the Microsoft.Net.Compiler 2.6.0 resolved the issue on VSTS. Thank you.

All 10 comments

@johnweeder Which version of VS or compiler toolset are you using? Please choose the analyzer package version as per https://github.com/dotnet/roslyn-analyzers/#recommended-version-of-analyzer-packages

Kindly re-activate if you are seeing this issue on 2.6.0 analyzer packages on VS 2017.5 RTW or later.

This issue does NOT arise on my local development machine running 15.5.4.
This issue DOES arise on VSTS builds.

1) I do NOT have codeanalysis enabled
2) Something attempts to load this assembly anyway during the build (d:\a\1\s\packages\Microsoft.CodeAnalysis.Analyzers.2.6.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll : Could not load file or assembly...) and
3) The build is loading from the PACKAGES folder instead of from the build tools.

(https://github.com/dotnet/roslyn-analyzers/files/1643953/CsProjAndPackagesConfig.zip)
[CsProjAndPackagesConfig.zip]

Please note that I am not even using Code Analysis during the builds. It is disabled in all assemblies.

This error only happens, apparently, because the assembly being built includes (indirectly via MVC) the 2.6.0 Microsoft.CodeQuality.Analyzers as a nuget. Only this particular assembly fails. All others build. If I revert to the 1.x version, the VSTS build works again.

@johnweeder Can you try to add a NuGet package reference to https://www.nuget.org/packages/Microsoft.Net.Compilers/2.6.1 to your project? This will ensure that the compiler toolset used to build your project will always be the same, regardless of what VS or VSTS build is installed.

I will try this. Please give me an hour or so. I am at lunch right now.

@mavasani Adding the Microsoft.Net.Compiler 2.6.0 resolved the issue on VSTS. Thank you.

@mavasani Surely adding a reference to 2.6.1 is not the proper, long term solution. What will happen when 3.0 comes out? Won't all the projects then be forced to use a 'legacy' compiler. How am I / the team supposed to know when it is the right time to remove it? Will be get a proper and clear message or some obfuscated code-speak not intelligible to ordinary developers for whom managing compiler issues is not part of their fob?
What is the proper fix?

(I have the same issue, and don' that adding 100+, to me, superfluous references is the right thing to do.)

Matt

Oh, and PS
get-project -all | Install-Package Microsoft.Net.Compilers -Version 2.6.0
reliably crashes with the following error:

Install-Package : The WriteObject and WriteError methods cannot be called from outside the overrides of the BeginProcessing, 
ProcessRecord, and EndProcessing methods, and they can only be called from within the same thread. Validate that the cmdlet makes these 
calls correctly, or contact Microsoft Customer Support Services.
At line:1 char:20
+ ... project -all | Install-Package Microsoft.Net.Compilers -Version 2.6.0
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], PSInvalidOperationException

Which particular

Microsoft Customer Support Services

am I supposed to phone?!

@Mattacks You cannot get best of both the worlds here. You can either configure your project to use a fixed compiler toolset or always use the compiler toolset that comes along with compiler/VS installed in the box. If you want to make sure that all the developers on the repo are always building the project with the same compiler toolset, you should take the former approach. If you want to always dogfood the latest version of the compiler toolset, you need to request all the developers on the repo to use a compiler/VS version which is equals or higher then the version of compiler APIs that the analyzer package was built against. So, for example, if your project references version 2.6.0 of FxCop analyzers package, you need to make sure that development on your repo happens on VS 15.5 or later (VS15.5 has compiler version 2.6).

@mavasani Thanks

awesome! works for me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

paulomorgado picture paulomorgado  路  3Comments

paulomorgado picture paulomorgado  路  3Comments

SixFive7 picture SixFive7  路  4Comments

lgolding picture lgolding  路  4Comments

paulomorgado picture paulomorgado  路  3Comments