Restore the ThisAssemblyClass module as an incremental source generator - #306
Conversation
Reintroduce the ThisAssemblyClass SDK module, removed in PR Tenacom#158, as a dormant module (GenerateThisAssemblyClass defaults to false) built on a Roslyn incremental source generator instead of the old compiled-task code generation. C# only: enabling the module in any other language raises the new BVSDK2300 warning. - ThisAssemblyConstant items are serialized by the new WriteThisAssemblyConstantsFile task into a percent-encoded constants file under obj/, exposed to the generator as a tagged AdditionalFiles item; class name and namespace flow through CompilerVisibleProperty. - ThisAssemblyClassGenerator emits the class with CompilerGenerated and ExcludeFromCodeCoverage attributes; invalid constant values raise BVSDK2301 as a compiler diagnostic (with analyzer release tracking). - The constant-value parser is restored into the source generators assembly as the single shared implementation; VB type aliases (Integer, Boolean) are gone along with all VB support. - Default constants and the EnableDefaultThisAssemblyConstants knob are preserved from the pre-removal module. - New Buildvana.Sdk.SourceGenerators.Tests project (generator + parser tests); task tests added to Buildvana.Sdk.Tasks.Tests. - ConstantsSyntax.md trimmed to ThisAssembly constants only; new ThisAssemblyClass diagnostics range (2300-2399) in SdkDiagnostics.md. - markdownlint config: move "ignores" to its documented top-level position (it was inert inside "config") and exempt the machine-parsed AnalyzerReleases.*.md files. Closes Tenacom#295 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
@claude please review this PR. |
|
Claude finished @rdeago's task in 4m 6s —— View job Claude finished reviewing this PRTasks:
SummarySolid implementation overall. The incremental-generator design is clean, the percent-encoding round trip between the task and the generator is airtight (verified the escaping logic handles Notes (non-blocking)
Nothing here blocks merging — items 1 and 3 are worth a quick gut-check from you, item 2 is optional polish. |
…nstants BV_DefineDefaultThisAssemblyConstants reads AssemblyVersion, FileVersion, and InformationalVersion, but those are computed by the GetAssemblyVersion target (with the source revision appended by AddSourceRevisionToInformationalVersion), which had no ordering relation with the constants-writing target: both hooked BeforeTargets=CoreCompile. Declare both as dependencies so the default constants never capture empty or incomplete version values. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…tyle The default constant for $(AssemblyVersion) was named Version, which is ambiguous: it could just as easily be read as the NuGet package version. Follow the naming convention of Nerdbank.GitVersioning ThisAssembly classes instead, where constants are named after the corresponding assembly attributes (AssemblyVersion, AssemblyFileVersion, AssemblyInformationalVersion, AssemblyTitle, and so on). Also add the AssemblyName, AssemblyConfiguration, and RootNamespace constants that NBGV provides and cost nothing to supply. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Thanks for the review — the findings have been addressed as follows:
@claude please take another look. |
|
Claude finished @rdeago's task in 1m 54s —— View job Follow-up review complete
SummaryOnly 1. Target ordering (4853167) — 2. BVSDK2301 location — agreed, leaving it as-is is the right call. The generator has no way to reach the originating 3. Default constant renaming (f38dfd6) — the No remaining concerns from me — this looks ready to merge. |
|
It should additionally be noted that the one issue found by CodeFactor (use of Substring where AsSpan would spare an allocation) is a false positive: the flagged code is part of a .NET Standard 2.0 project, where AsSpan is not available. |
Proposed changes
WHY — Versioning Phase 6 (#295, sub-issue of #267): the
ThisAssemblyClassmodule, removed in #158 along with the task-based code generation, returns as the future home of native version constants (Phase 7 will feed it version values). It lands dormant —GenerateThisAssemblyClassdefaults tofalse— so no project, including this self-hosted repo, changes behavior, and there is no collision with NBGV'sThisAssembly.WHERE — SDK module targets (
Modules/ThisAssemblyClass),Buildvana.Sdk.SourceGenerators,Buildvana.Sdk.Tasks, docs, and a newBuildvana.Sdk.SourceGenerators.Testsproject.WHAT — A C# project opting in with
GenerateThisAssemblyClass=truegets a generatedinternal static partialThisAssemblyclass (name/namespace configurable viaThisAssemblyClassName/ThisAssemblyClassNamespace) withCompilerGeneratedandExcludeFromCodeCoverageattributes, containingpublic constfields fromThisAssemblyConstantitems plus the eight default constants (honoringEnableDefaultThisAssemblyConstants). C# only: any other language raises the new BVSDK2300 warning; invalid constant values raise BVSDK2301 as a compiler diagnostic. VB support is not restored, down to the parser's oldInteger/Booleantype aliases.HOW — Unlike the pre-#158 compiled-task design, generation happens in a Roslyn incremental source generator: IntelliSense sees the class without building, incrementality is content-keyed for free, and no generated
.csfile inobj/can go stale. Since generators cannot see MSBuild items — and version values are computed by targets, too late forCompilerVisibleProperty— a smallWriteThisAssemblyConstantsFiletask serializes the constants (percent-encodedname=valuelines, written only on change) into a taggedAdditionalFilesitem the generator reads. The restoredtype:valueparser lives in the generators assembly as the single shared implementation. Reporting a generator diagnostic required analyzer release tracking (AnalyzerReleases.*.md); those files' format is machine-parsed and cannot satisfy markdownlint, so they are excluded in.markdownlint-cli2.jsonc— which also fixes that config'signoresoption, previously nested insideconfigwhere it had no effect.Sanity check:
dotnet bv packclean, 84 tests green (51 new generator/parser + 6 new task tests), ReSharper inspectcode reports nothing in changed code, markdownlint clean on all touched files.Checklist of related issues / discussions
ThisAssemblyClassSDK module and source generator #295Types of changes
This pull request introduces the following types of changes:
docsdirectory) updateOther: markdownlint configuration fix (misplaced
ignoresoption).Breaking changes
This pull request introduces breaking changes:
Checklist
docsdirectory) only:🤖 Generated with Claude Code