Skip to content

Move attribute types to source generation, remove lib/ from package#193

Open
fm39hz wants to merge 1 commit into
Cat-Lips:mainfrom
fm39hz:main
Open

Move attribute types to source generation, remove lib/ from package#193
fm39hz wants to merge 1 commit into
Cat-Lips:mainfrom
fm39hz:main

Conversation

@fm39hz

@fm39hz fm39hz commented Jun 14, 2026

Copy link
Copy Markdown

Problem

Attribute types (SceneTree, Autoload, Notify, etc.) are compiled into lib/netstandard2.0/, creating a runtime dependency on GodotSharp.SourceGenerators.dll. When the assembly is loaded at runtime, the CLR tries to resolve its dependencies (Scriban, Microsoft.CodeAnalysis, CsvTextFieldParser), which fail because they are build-time-only analyzer dependencies. This produces 'Failed loading Assembly' warnings in the Godot console.

Solution

Emit all attribute types and supporting types (Scope, ResG, ResI, Generate, IResourceTreeConfig, ICodeComments) via RegisterPostInitializationOutput as generated source code in consuming projects. This eliminates the need for lib/netstandard2.0/ in the NuGet package.

Changes

  • Shared/AttributeTypeEmitter.cs — new [Generator] that emits all attribute types before incremental generators run
  • Shared/AttributeTypeSources.cs — 24 verbatim source constants for attributes and shared types
  • SourceGenerators.csproj — set IncludeBuildOutput=false, suppress NU5128

Result

  • Package ships DLL only in analyzers/dotnet/cs/
  • No lib/netstandard2.0/ → no runtime dependency
  • Attribute types are available at compile time via generated source
  • Same API surface, zero behavioral change for consumers

Copilot AI review requested due to automatic review settings June 14, 2026 10:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Attribute types (SceneTree, Autoload, Notify, etc.) were compiled into
lib/netstandard2.0/ causing runtime assembly resolution failures for
their Scriban/Microsoft.CodeAnalysis dependencies.

Fix: emit all attribute types via RegisterPostInitializationOutput
(AttributeTypeEmitter), so consuming projects get them as generated
source code. Set IncludeBuildOutput=false so the analyzer DLL ships
only in analyzers/dotnet/cs/, not lib/.
@fm39hz fm39hz changed the title #193 Move attribute types to source generation, remove lib/ from package Move attribute types to source generation, remove lib/ from package Jun 14, 2026
@Cat-Lips

Copy link
Copy Markdown
Owner

Hi.

As a source generator, the dll and dependencies shouldn't be required or even copied to the build output folder.

I tried creating a fresh project in Godot 4.6.3, adding GodotSharp.SourceGenerators 2.7.0 via nuget and adding [SceneTree] to the main scene. It built and ran ok from within the Godot Editor and the dll wasn't copied.

Could you pls upload a minimal build that causes the problem (or instructions to replicate)?

Thanks :)

@fm39hz

fm39hz commented Jun 15, 2026

Copy link
Copy Markdown
Author

Repro setup that triggers it:

  • Package version: 2.7.0-260429-2100.Release (the auto daily build) — the stable 2.7.0 from nuget.org may behave differently
  • SDK: .NET 10, Godot.NET.Sdk 4.6.2
  • csproj: <EnableDynamicLoading>true</EnableDynamicLoading>
  • Run: godot --path . (outside Editor)

With EnableDynamicLoading=true, the .NET SDK treats the package's lib/netstandard2.0/ as a runtime dependency → GodotSharp.SourceGenerators.dll ends up in the build output + .deps.json. When Godot loads it, the CLR tries to resolve Scriban/Microsoft.CodeAnalysis/CsvTextFieldParser (build-time analyzer deps) → 'Failed loading Assembly'.

That said, the PR already fixes the root cause — removing lib/ from the package entirely via IncludeBuildOutput=false is the correct approach regardless of SDK/environment differences. The attribute types are emitted via source gen, so consumers never need the DLL at runtime.

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.

3 participants