Skip to content

Fix RS1038 build errors in analyzer and source generator projects - #48

Open
cobriensr wants to merge 1 commit into
godotengine:masterfrom
cobriensr:fix-rs1038-analyzer-workspaces
Open

Fix RS1038 build errors in analyzer and source generator projects#48
cobriensr wants to merge 1 commit into
godotengine:masterfrom
cobriensr:fix-rs1038-analyzer-workspaces

Conversation

@cobriensr

@cobriensr cobriensr commented Jul 18, 2026

Copy link
Copy Markdown

Problem

Building the repository from a clean checkout (build.cmd/build.sh) with the pinned .NET SDK fails with RS1038 errors in Godot.Analyzers and Godot.SourceGeneration:

error RS1038: This compiler extension should not be implemented in an assembly
containing a reference to Microsoft.CodeAnalysis.Workspaces. ...

Both projects set EnforceExtendedAnalyzerRules and import the shared Godot.Common.CodeAnalysis code, which references Microsoft.CodeAnalysis.CSharp.Workspaces. RS1038 flags this because the Workspaces assembly is not available during command-line compilation.

Fix

Suppress RS1038 in both projects with an explanatory comment, matching the convention already used in Godot.UpgradeAssistant.Providers:

  • Godot.Analyzers genuinely needs Workspaces for its code-fix providers (CodeFixers/), which run in the IDE where Workspaces is available.
  • Godot.SourceGeneration inherits the reference through the shared code but does not use any Workspaces APIs, so the reference is harmless during command-line compilation.

Alternative considered

I also tried moving the Workspaces reference out of the shared Godot.Common.CodeAnalysis.projitems (so the source generator would not reference Workspaces at all). This resolves RS1038, but removing that reference also removes a version anchor and the dependency graph falls back to a very old, .NET Framework-only Microsoft.CodeAnalysis.CSharp.Workspaces 1.0.1, producing NU1701 errors. A proper split of the shared analysis code (so analyzers and code fixes live in separate assemblies) would be a larger change.

Testing

Verified locally on Windows with .NET SDK 10.0.103: build.cmd now compiles Godot.Analyzers and Godot.SourceGeneration with no RS1038 errors, and the unit test suite passes.

Godot.Analyzers and Godot.SourceGeneration set EnforceExtendedAnalyzerRules
and import the shared Godot.Common.CodeAnalysis code, which references
Microsoft.CodeAnalysis.CSharp.Workspaces. RS1038 reports this as an error
because Workspaces is not available during command-line compilation, which
breaks the build from a clean checkout.

Godot.Analyzers genuinely needs Workspaces for its code-fix providers (which
run in the IDE where Workspaces is available), and Godot.SourceGeneration
inherits the reference through the shared code without using any Workspaces
APIs. Suppress RS1038 in both projects with an explanatory comment, matching
the existing convention already used in Godot.UpgradeAssistant.Providers.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant