Support `Sentry.SourceGenerators` via Visual Studio 2019 version 16.11
Environment
SaaS (https://sentry.io/)
Steps to Reproduce
When building UWP project using Azure DevOps Pipelines we got this error:
Error CS8032: An instance of analyzer Sentry.SourceGenerators.BuildPropertySourceGenerator cannot be created from C:\Users\svcprd_tfbuild.nuget\packages\sentry\5.15.1\analyzers\dotnet\cs\Sentry.SourceGenerators.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
Microsoft.CodeAnalysis Version=4.3.0.0 is not available in Nuget repository.
Sentry Version=5.15.1
EDIT: TreatWarningAsErrors is set to true, so this error is acutally a warning: CSC : warning CS8032: An instance of analyzer Sentry.SourceGenerators.BuildPropertySourceGenerator cannot be created from C:\Users\svcprd_tfbuild.nuget\packages\sentry\5.14.1\analyzers\dotnet\cs\Sentry.SourceGenerators.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
Expected Result
Build should finish without problems.
Actual Result
Build fails with error described above
Product Area
Unknown
Link
No response
DSN
No response
Version
No response
Assigning to @getsentry/support for routing ⏲️
Thanks @KrzysztofFryzlewicz for reporting this issue.
One aspect that catches my eye is that you mentioned using v5.15.1 of the SDK,
but the error contains \5.14.1\.
Not sure if there is a restore issue, or just a message from a build before the version update.
Anyway, we need a bit more info about the environment to reproduce the error:
- which version of the .NET SDK / Visual Studio / MSBuild is used on your Azure Pipelines agent?
I have the feeling that this is less of an UWP problem, but more of an issue related to compatibility with MSBuild and the available Roslyn Compiler version.
@Flash0ver yeah, issue exists in 5.14.1 and then I upgraded the package to see if this resolves anything, but no luck. MSBuild version: 16.0 Visual Studio 2019
We excluded this warning and build seems to run just fine.
Thanks for your rapid reply, @KrzysztofFryzlewicz.
Which Visual Studio exactly? Although, doesn't really matter. Visual Studio 16.11.nn supports/includes the .NET SDK 5.0.4nn, which supports C# 9.0 and the Compiler (Roslyn) in version 3.11.
The issue is that the Roslyn Compiler Extension that we ship requires 4.3, and therefore you receive the Warning CS8032.
Your issue is now pushing the priority of #4305.
But #4305 is a bit more effort, and may not justify this scenario. Well, I'm a bit uncertain about that part actually: on the one hand .NET 5.0 has reached end of life, but on the other hand Visual Studio 2019 version 16.11 reaches End of Support in April 2029. So, actually, for scenarios like the one that you are having, we eventually should implement #4305. Especially considering the current ecosystem, where broadly used Source-Generators like the ones included in System.Text.Json and Microsoft.Extensions.Logging.Abstractions support roslyn3.11 (alongside roslyn4.0 and roslyn4.4).
In order for our Source-Generator to support Roslyn 3.11, we need multi-targeting to not break existing scenarios, as that version is missing the Microsoft.CodeAnalysis.Diagnostics.AnalyzerConfigOptions.Keys member.
As a matter of fact, currently, in a personal project, I am exploring multi-targeting for Roslyn components and working on an MSBuild target that facilitates that process. But I need a bit more time on that to sort it out. I'll keep you posted.
We can close this issue, we did a workaround and it will probably resolve itself in the future. Thanks!
In the meantime, I wonder if either of these workarounds could help you temporarily, until we provide proper multi-targeting:
Not consuming the .NET Analyzer assets that we provide.
<ItemGroup>
<PackageReference Include="Sentry" Version="5.15.1">
<ExcludeAssets>analyzers</ExcludeAssets>
</PackageReference>
</ItemGroup>
Or suppressing the warning for now
<ItemGroup>
<PackageReference Include="Sentry" Version="5.15.1" NoWarn="CS8032" />
</ItemGroup>
So that you can still enable TreatWarningsAsErrors globally.
I like the latter one, perfect!
We can close this issue, we did a workaround and it will probably resolve itself in the future. Thanks!
I'd like to keep it open, at least for now, as we do indeed need to support building supported Projects from Visual Studio 16.11. May merge later into #4305.
#4569 is now reporting this issue in CI