You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So that older hosts won't load the Roslyn Component, and newer hosts can choose a compatible version.
E.g. fixes issues like
An instance of analyzer Sentry.SourceGenerators.BuildPropertySourceGenerator cannot be created from {..}\.nuget\packages\sentry\5.11.0\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..
Thanks for the hint, @aritchie. And most welcome it is indeed!❗️
We're looking into expanding the source generator to enable #3212 via #4330.
But I just realize that we would conflate concerns here.
The Build-Properties are intended to detect NativeAOT, for NET7_0_OR_GREATER.
But Auto-Debug-Mode could/should work regardless of the TFM.
So this should really be two different source generators.
And perhaps the existing BuildPropertySourceGenerator should be renamed and repurposed to NativeAotGenerator, generating code that sets a Native-AOT flag to true when #if NET7_0_OR_GREATER.
And another AutoDebugGenerator should then generate code that sets a Auto-Debug flag to true when #if DEBUG.
So that we don't depend on Build-Properties being exposed publicly, where the Source-Generator could already evaluate the Build-Properties at Compile-Time, and we don't pay the price of allocating and performing a lookup at run-time.
It looks like there might not be any clean way to implement auto-debug (see comment)... in which case, the only thing we'd be using the source generators for is to detect AOT compilation settings.
Activity
aritchie commentedon Jul 11, 2025
Only .NET 7 and up compile AOT which was the main reason for the source generators. Just an FYI unless you're looking to expand on what it does.
Flash0ver commentedon Jul 11, 2025
Thanks for the hint, @aritchie. And most welcome it is indeed!❗️
We're looking into expanding the source generator to enable #3212 via #4330.
But I just realize that we would conflate concerns here.
The Build-Properties are intended to detect NativeAOT, for
NET7_0_OR_GREATER.But Auto-Debug-Mode could/should work regardless of the TFM.
So this should really be two different source generators.
And perhaps the existing
BuildPropertySourceGeneratorshould be renamed and repurposed toNativeAotGenerator, generating code that sets a Native-AOT flag totruewhen#if NET7_0_OR_GREATER.And another
AutoDebugGeneratorshould then generate code that sets a Auto-Debug flag totruewhen#if DEBUG.So that we don't depend on Build-Properties being exposed publicly, where the Source-Generator could already evaluate the Build-Properties at Compile-Time, and we don't pay the price of allocating and performing a lookup at run-time.
jamescrosswell commentedon Jul 13, 2025
It looks like there might not be any clean way to implement auto-debug (see comment)... in which case, the only thing we'd be using the source generators for is to detect AOT compilation settings.