Emit attributes into the consuming compilation - #8
Merged
Conversation
The package set DevelopmentDependency=true while also shipping EnumGenerator.Attributes.dll in lib/netstandard2.0. NuGet writes "runtime; build; native; contentfiles; analyzers; buildtransitive" for a development dependency -- note the absent "compile" -- so the attributes assembly was invisible to consumers, who had to hand-edit IncludeAssets after every install. Resolve the contradiction in favour of the package genuinely being a development dependency: AttributeSourceUtils now holds the attribute source, which EnumIncrementalGenerator emits via RegisterPostInitializationOutput. Post-initialization is mandatory here, since both providers resolve [GenerateEnumUtilities] through the semantic model, which only sees post-initialization sources during the run. The EnumGenerator.Attributes project is gone, and the package now contains nothing but the generator in analyzers/dotnet/cs. Consumers get no lib/ folder, no assembly to reference, and no runtime dependency. Also fixes two packaging bugs found along the way: the packaging project's own empty assembly was leaking into lib/ (IncludeBuildOutput), and the empty dependency group tripped NU5128 once lib/ was removed (SuppressDependenciesWhenPacking). EnumGenerator.Tests.NuGetIntegration now declares the exact metadata `dotnet add package` writes rather than the hand-patched version, so it regression-tests a default install. The attributes change from public in a referenced assembly to internal in each compilation, hence the minor version bump to 0.6.0. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1.
The problem
EnumGenerator.PackagesetDevelopmentDependency=truewhile also shippingEnumGenerator.Attributes.dllinlib/netstandard2.0. NuGet writes this on install for a development dependency:Note the absent
compile. The attributes assembly was therefore invisible to consumers, who had to hand-addcompileafter every install. The package was claiming "nothing to reference" while shipping something to reference.The fix
Rather than push consumers toward including the
compileasset (which is what the issue title suggests), this removes the need for it entirely — the package becomes a genuine development dependency.AttributeSourceUtilsnow holds the attribute source, whichEnumIncrementalGeneratoremits viaRegisterPostInitializationOutput. Post-initialization is mandatory here: both providers resolve[GenerateEnumUtilities]through the semantic model, and only post-initialization sources are visible to it during the generator run. Moving this toRegisterSourceOutputwould silently break all detection.The
EnumGenerator.Attributesproject is deleted. The package now contains nothing but the generator:No
lib/folder, no assembly to reference, no runtime dependency, and the defaultPackageReferenceneeds no editing.Two packaging bugs found while verifying are fixed alongside:
lib/netstandard2.0/EnumGenerator.Package.dll— the packaging project's own empty assembly was leaking into the package (IncludeBuildOutput=false).netstandard2.0dependency group tripped NU5128 oncelib/was gone (SuppressDependenciesWhenPacking=true).Verification
EnumGenerator.Tests.NuGetIntegrationnow declares the exact metadatadotnet add packagewrites, instead of the hand-patched version withcompilebolted on. It is the regression test for this issue — if it stops compiling, the package layout is wrong, not the test.IncludeAssets): 13/13.EnumGenerator.Sampleruns correctly.Breaking change
The attributes go from
publicin a referenced assembly tointernalin each compilation. This only matters for code that reflects overGenerateEnumUtilitiesAttributeat runtime or re-exposes it across assembly boundaries — unlikely, since the attribute only drives generation. Version bumped to 0.6.0 accordingly.No new constraint on consumers: the generic
GenerateEnumUtilitiesAttribute<T>needs C# 11, which the README already requires for UTF-8 literals andEnum.GetValues<T>().🤖 Generated with Claude Code