Skip to content

Multi-target Roslyn Compiler Extensions #4305

Open

Description

@Flash0ver

Description

We don't know under which environment the user is hosting Roslyn when building a project that depends on Sentry.

  • .NET SDK version
  • "Full"-Framework MSBuild
  • custom Host

See dotnet/sdk#20355

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..

Examples

Activity

  1. added
    .NETPull requests that update .net code
    on Jun 25, 2025
  2. added
    RoslynThe .NET Compiler Platform, Roslyn Components and Extensions, Microsoft.CodeAnalysis
    on Jun 25, 2025
  3. aritchie commented on Jul 11, 2025

    @aritchie
    Contributor

    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.

  4. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jul 11, 2025
  5. Flash0ver commented on Jul 11, 2025

    @Flash0ver
    ContributorAuthor

    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.

  6. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jul 11, 2025
  7. jamescrosswell commented on Jul 13, 2025

    @jamescrosswell
    Collaborator

    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.

  8. self-assigned this
    on Oct 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETPull requests that update .net codeImprovementRoslynThe .NET Compiler Platform, Roslyn Components and Extensions, Microsoft.CodeAnalysis

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions