Skip to content

Analyzer-specific properties in eng/Analyzer.props are evaluated before IsAnalyzerProject is set #15322

Open

Description

@KlausLoeffelmann

Issue description

Follow-up discovered while investigating #15314; separate from its architecture-routing fix.

Directory.Build.props imports eng/Analyzer.props before the project body is evaluated. eng/Analyzer.props defaults IsAnalyzerProject to false and immediately conditions a property group on it being true. However, the analyzer/code-fix projects declare <IsAnalyzerProject>true</IsAnalyzerProject> in their project bodies, after that import.

Consequently, the conditional group is skipped and is not reevaluated when the project later sets the property. Its intended settings do not take effect:

<PropertyGroup Condition="'$(IsAnalyzerProject)' == 'true'">
  <IsRoslynComponent>true</IsRoslynComponent>
  <DefineConstants>WINFORMS_ANALYZERS</DefineConstants>
</PropertyGroup>

This means the projects are marked as analyzer projects by the end of evaluation, but lack the intended Roslyn-component marker and compilation symbol. No additional runtime or packaging failure is claimed here; the confirmed defect is the missing evaluated properties.

Steps to reproduce

In a restored checkout, run:

dotnet msbuild src\System.Windows.Forms.Analyzers\src\System.Windows.Forms.Analyzers.csproj -getProperty:IsAnalyzerProject,IsRoslynComponent,DefineConstants -nologo

Observed:

{
  "Properties": {
    "IsAnalyzerProject": "true",
    "IsRoslynComponent": "",
    "DefineConstants": "TRACE;DEBUG"
  }
}

Expected: IsRoslynComponent=true, and DefineConstants includes WINFORMS_ANALYZERS while preserving existing symbols.

Suggested scope

Apply analyzer-dependent settings after the project has declared IsAnalyzerProject (for example, in the existing analyzer targets mechanism), preserving any existing compilation symbols. Add evaluation regression coverage for the C# and VB analyzer/code-fix projects, plus a non-analyzer control project.

.NET version

Reproduced with the repository-pinned SDK 12.0.100-alpha.1.26480.102 during investigation of #15314.

Did it work in .NET Framework?

Not applicable: repository MSBuild evaluation issue.

Did it work in any earlier release?

Not verified; this appears to predate the changes in #15314.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions