Skip to content

Commit 0e5aac9

Browse files
csharpfritzCopilot
andcommitted
fix(docker): strip NBGV in Docker build for correct version stamping
NBGV unconditionally overrides -p:InformationalVersion when its MSBuild task runs. Since .dockerignore excludes .git, NBGV falls back to a stale version. Fix: sed removes the NBGV PackageReference from Directory.Build.props inside the Docker build stage, letting the explicit VERSION build arg take effect. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 194f528 commit 0e5aac9

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

.ai-team/agents/forge/history.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,19 @@ Planned M12: "Migration Analysis Tool (PoC)" — 13 work items. A CLI tool (`bwf
130130

131131
📌 Team update (2026-02-25): CI secret-gating pattern corrected — secrets.* cannot be used in step-level if: conditions. Use env var indirection: declare secret in env:, check env.VAR_NAME in if:. Applied to nuget.yml and deploy-server-side.yml (PR #372). — decided by Forge
132132

133+
### Summary: NBGV Docker Version Stamping Fix (2026-02-25)
134+
135+
**Root cause:** NBGV (Nerdbank.GitVersioning 3.9.50) overrides externally-passed `-p:InformationalVersion` inside Docker, even when `.git` is excluded by `.dockerignore`. The mechanism:
136+
137+
1. NBGV's targets (`Nerdbank.GitVersioning.targets` line 28) set `GenerateAssemblyInformationalVersionAttribute=false`, suppressing the SDK's attribute generation.
138+
2. NBGV's `GetBuildVersion` task (`Nerdbank.GitVersioning.Inner.targets` line 34) unconditionally overwrites `AssemblyInformationalVersion` via `<Output>` during build execution — this overrides even `-p:` global properties.
139+
3. NBGV's `GenerateAssemblyNBGVVersionInfo` target generates its own assembly version source file using NBGV's computed value (from `version.json` fallback when no `.git`).
140+
141+
Result: The `BlazorWebFormsComponents` assembly gets stamped with NBGV's fallback version (e.g., `0.13.0` from old version.json) instead of the precise version computed by nbgv outside Docker.
142+
143+
**Fix:** Added `sed` command in `samples/AfterBlazorServerSide/Dockerfile` after `COPY . .` to strip the NBGV PackageReference from `Directory.Build.props` inside the Docker build. This completely removes NBGV from the build, allowing the SDK's default attribute generation to use the `-p:InformationalVersion=$VERSION` property passed from the workflow. The `dotnet build` implicit restore handles the changed project metadata automatically.
144+
145+
**Key insight:** You cannot override NBGV's version stamping via `-p:` properties alone. NBGV's MSBuild task outputs overwrite properties during execution (not evaluation), bypassing global property precedence. The only reliable fix is to remove NBGV from the build when git history is unavailable and version is injected externally.
146+
147+
📌 Team update (2026-02-25): Docker NBGV fix — strip NBGV PackageReference inside Docker build via sed. NBGV cannot be overridden by -p: properties; must be removed entirely when .git is unavailable. — decided by Forge
148+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
### 2026-02-25: Strip NBGV from Docker build to fix version stamping
2+
3+
**By:** Forge
4+
5+
**What:** Added `sed` command in `samples/AfterBlazorServerSide/Dockerfile` (after `COPY . .`, before `dotnet build`) to remove the `Nerdbank.GitVersioning` PackageReference from `Directory.Build.props` inside the Docker build context. This allows the SDK's default assembly attribute generation to use the externally-passed `-p:Version=$VERSION -p:InformationalVersion=$VERSION` properties without NBGV interference.
6+
7+
**Why:** NBGV's MSBuild targets unconditionally override version properties during build execution via task `<Output>` elements, which bypass MSBuild global property (`-p:`) precedence. Inside Docker (where `.git` is excluded by `.dockerignore`), NBGV falls back to `version.json` and stamps assemblies with a stale/inaccurate version instead of the precise version computed by `nbgv get-version` in the workflow. No combination of `-p:` properties can reliably prevent this because NBGV: (1) suppresses SDK attribute generation, (2) overwrites `AssemblyInformationalVersion` during execution, and (3) generates its own attribute source file. The only reliable fix is to remove NBGV entirely from the Docker build, which is safe because all projects only depend on NBGV transitively through `Directory.Build.props` — none reference NBGV properties directly.

samples/AfterBlazorServerSide/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ COPY ["src/BlazorWebFormsComponents/BlazorWebFormsComponents.csproj", "src/Blazo
1414
COPY ["samples/SharedSampleObjects/SharedSampleObjects.csproj", "samples/SharedSampleObjects/"]
1515
RUN dotnet restore "samples/AfterBlazorServerSide/AfterBlazorServerSide.csproj"
1616
COPY . .
17+
# Remove NBGV - not functional in Docker without .git; version is injected via VERSION build arg
18+
RUN sed -i '/<PackageReference Include="Nerdbank.GitVersioning"/,/<\/PackageReference>/d' Directory.Build.props
1719
WORKDIR "/src/samples/AfterBlazorServerSide"
1820
RUN dotnet build "AfterBlazorServerSide.csproj" -c Release -o /app/build -p:Version=$VERSION -p:InformationalVersion=$VERSION
1921

0 commit comments

Comments
 (0)