Skip to content

Enable Analyzers when building source-only #115397

Open

Description

@ViktorHofer

#115395 showed new CA2025 errors but only in the non-source-only jobs. That's because analyzers are disabled globally when building source-only:

<RunAnalyzers Condition="'$(DotNetBuildSourceOnly)' == 'true'">false</RunAnalyzers>

This setting dates back to dotnet/corefx@7732d6b which disabled analyzers for source-only builds.

This is problematic for various reasons:

  • Creates an artificial difference between source-only and non-source-only builds
  • Diverging behavior form other repositories which don't disable analyzers when building source-only
  • Doesn't get caught in SB's stage2 validation that runs as part of VMR PRs. For the above PR that meant it only get caught in the VMR -> runtime backflow PR and not in the roslyn-analyzers -> VMR forward flow PR.

I propose that we change this setting to only apply to "online" analyzers that don't exist in the source-build graph.

cc @dotnet/source-build @ericstj (as you made the original commit) for opinions

Activity

  1. added
    untriaged
    on May 8, 2025
  2. added
    needs-area-label
    on May 8, 2025
  3. MichaelSimons commented on May 8, 2025

    @MichaelSimons
    Member

    Analyzers have historically been problematic in the past for source-build for projects targeting older TFMs because the targeting packs from SBRP exclude the analyzers. The targeting pack analyzers can't reasonable be built from source. We are in a much better place today with the introduction of NetCurrent. Ideally differences like this wouldn't exist. It should be easy to validate what the impact is of enabling this within the VMR.

  4. added and removed
    untriaged
    needs-area-label
    on May 8, 2025
  5. added this to the 10.0.0 milestone on May 8, 2025
  6. dotnet-policy-service commented on May 8, 2025

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/runtime-infrastructure
    See info in area-owners.md if you want to be subscribed.

  7. ericstj commented on May 8, 2025

    @ericstj
    Member

    At the time of the commit you linked we were fixing prebuilts -- dotnet/source-build#884

    Not sure I agree that change was from then - I see e0e1919 renamed the property to apply to all analyzers.
    Before that 42183b1#diff-489b1e12d93a4928641f4e40fc9d33fe0490b257176f4f055c901dbfc8b751e5R5 added it as EnableAnalyzers which might have been our own property that controlled some package references to things that were likely not "below runtime" in the source build graph.

    Seems like #42272 (comment) might cover this.

  8. ViktorHofer commented on May 8, 2025

    @ViktorHofer
    MemberAuthor

    Thanks Eric and Michael for sharing context.

    The analyzer that made me open this issue is Microsoft.CodeAnalysis.NetAnalyzers which got disabled by that commit. That triggered an analyzer error in today's dotnet -> runtime backflow PR instead of at insertion time in the roslyn-analyzers -> VMR forward flow PR in the source-build stage2 job.

    If I don't hear any objections to re-enabling the analyzers when building source-only, I will send a PR re-enabling them (maybe first in the VMR as Michael suggested).

  9. modified the milestones: 10.0.0, Future on Aug 25, 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

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions