Myself as well as my coworkers all started seeing this problem sometime in the last few weeks:
Build FAILED
CSC : warning CS8032: An instance of analyzer My.Company.Generators.ReportingV2Generator cannot be created from /Users/work/dev/git/reporting-model/src/My.Company.Generators/bin/Debug/netstandard2.1/My.Company.Generators.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.10.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.. [/Users/work/dev/git/reporting-model/src/My.Team.Models.ReportingV2/My.Team.Models.ReportingV2.csproj]
/Users/work/dev/git/reporting-model/src/My.Company.Api/SmokeTests/Tests/ContentAskExpertSmokeTest.cs(7,20): error CS0234: The type or namespace name 'Models' does not exist in the namespace 'My.Team' (are you missing an assembly reference?) [/Users/work/dev/git/reporting-model/src/My.Company.Api/My.Company.Api.csproj]
... Many more of the above "type or namespace" errors
...
This happens on both macOS and Windows. It works on Linux (both on a personal machine and inside mcr.microsoft.com/dotnet/sdk:5.0
.
Literally none of the source generator code / csproj has changed, it started spontaneously around two weeks ago. I can reproduce this on a commit from two months ago too, so it seems like something might have changed externally in the packages?
I found the solution for this by going to Microsoft directly.
The error on the failure case is that the generator is dependent on Microsoft.CodeAnalysis.dll version 3.10, and 3.10 only shipped in 5.0.300. It appears that your success case is using SDK 5.0.300 but the failure case is using 5.0.204.
You have two options to fix this:
If you're not using any of the features introduced in 3.10 for source generators, you can lower the Microsoft.CodeAnalysis nuget package target to 3.9 Ensure that all builds are using at least 5.0.300 version of the SDK