Repository navigation
Write a source file's global attributes after its usings [patch] - #148
Merged
matt-edmondson merged 1 commit intoOct 30, 2026
Merged
Conversation
AddSourceFile wrote the template's attributes first, so a file with both attributes and usings put [assembly: X] above the usings (CS1529) or outside the file-scoped namespace the usings were in (CS0246). When the file has attributes it now writes the usings, then the attributes, then the namespace. A file without attributes renders as before. Fixes #143 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW3gZxmT7yZRzkmnHAX
|
matt-edmondson
deleted the
claude/issue-143-file-attributes-after-usings
branch
October 30, 2026 02:40
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 #143
What changed
SourceFileTemplateExtensions.AddSourceFileused to write the template's attributes first, throughAddTemplate, and then the namespace and the usings. A file-level attribute can only be global (assembly:/module:), so any file that set bothAttributesandUsingsfailed to compile: CS1529 with no namespace, and CS0246 with one, because the attribute sat outside the namespace the usings were declared in.ASourceFileWritesItsPreambleThenItsTypestest are unchanged.<remarks>explaining the ordering.Keywordson a file template. That would be a behaviour change beyond this bug.Tests
TemplateTests:ASourceFileWritesItsGlobalAttributesAfterItsUsingsAndBeforeItsNamespaceandASourceFileWithNoNamespaceWritesItsGlobalAttributesAfterItsUsings.net10.0class library. Both build cleanly.Generated by Claude Code