Skip to content

[monobuild] Guard 'Get build revision number' against non-date build numbers (fix Foundation stage) - #6649

Draft
kythant wants to merge 2 commits into
release/dev/monobuildfrom
user/kythant/foundation-monobuild-buildrevision
Draft

[monobuild] Guard 'Get build revision number' against non-date build numbers (fix Foundation stage)#6649
kythant wants to merge 2 commits into
release/dev/monobuildfrom
user/kythant/foundation-monobuild-buildrevision

Conversation

@kythant

@kythant kythant commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix the Foundation stage crash in the WindowsAppSDK mono-build. The build-revision extraction throws Substring ... StartIndex cannot be less than zero on the mono-build's short semantic build number.

Root cause

Two copies of the same logic slice yyMM / dd / revision out of BUILD_BUILDNUMBER with fixed end-offsets (length - 10 / -5 / -3), which assume the standalone pipeline-name scheme $(date:yyMM).$(date:dd)$(rev:rrr) (>= 10 chars):

  1. build/AzurePipelinesTemplates/WindowsAppSDK-SetupBuildEnvironment-Steps.yml (the Get build revision number step) -- sets builddate / buildrevision pipeline variables. These are a dead duplicate (consumed nowhere in the repo).
  2. BuildAll.ps1 -- the REAL consumer: the extracted values feed /p:WindowsAppSDKVersionBuild + /p:WindowsAppSDKVersionRevision, which stamp the Foundation binary/package version.

The mono-build passes a short semantic build number (Official = "2.0.0", 5 chars), so length - 10 is negative and Substring throws. The Get build revision number step crashes first (observed in Official mono-build 152839452, failing every Build Foundation / Build MRT job; the Not found SourceFolder ...\BuildOutput errors are cascades) -- and BuildAll.ps1 would crash the same way right after. The Nightly did not hit this because its build number (2.0.0-dev.experimentalNNN) is > 10 chars.

Fix

Guard both copies behind a length >= 10 check; otherwise fall back to zero date/revision (and log it). Exact behavior is preserved for the date-based standalone build numbers; only the previously-crashing short-number (mono-build) path changes.

Why zeros are safe

In the mono-build Foundation is versioned from $(WindowsAppSDKFormattedVersion), and the Nightly already ran green producing throwaway values from its longer build number -- so these date/revision values do not drive the shipped version. The YAML step's builddate/buildrevision variables are unused entirely.

Validation

  • Both guarded PowerShell blocks parse with 0 errors.
  • Diffs are content-only apart from the intentional re-indent of the 3 extraction lines into each new if block; SetupBuildEnvironment-Steps.yml stays pure CRLF, BuildAll.ps1 stays pure LF.
  • Targets release/dev/monobuild (the branch the mono-build checks Foundation out at).

…numbers

The Foundation stage of the Official mono-build (build 152839452) fails in every
Build Foundation / Build MRT job at 'Get build revision number' with:
  Exception calling "Substring" with "2" argument(s): "StartIndex cannot be less than zero."

WindowsAppSDK-SetupBuildEnvironment-Steps.yml extracts yyMM/dd/revision from BUILD_BUILDNUMBER
using fixed end-offsets (length - 10 / -5 / -3), which assumes the standalone pipeline-name
scheme $(date:yyMM).$(date:dd)$(rev:rrr) (>=10 chars). The mono-build passes a short semantic
build number (Official "2.0.0", 5 chars), so length - 10 is negative and Substring throws,
failing the whole Foundation stage (the later 'Not found SourceFolder ...\BuildOutput' errors
are cascades of the aborted build).

These builddate/buildrevision variables are set here and consumed nowhere else in the repo, and
in the mono-build Foundation is versioned from $(WindowsAppSDKFormattedVersion), so the values
are unused there (the Nightly mono-build already ran green producing throwaway values from its
longer build number). Guard the fixed-offset extraction behind a length >= 10 check and fall back
to zero date/revision otherwise. Preserves exact behavior for the date-based standalone build
numbers.
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

BuildAll.ps1 (the actual Foundation build script) has an identical copy of the
BUILD_BUILDNUMBER Substring logic, and it is the REAL consumer of the value: the extracted
yymm/dd/revision feed /p:WindowsAppSDKVersionBuild + /p:WindowsAppSDKVersionRevision, which
stamp the Foundation binary/package version. (The builddate/buildrevision pipeline variables
set in WindowsAppSDK-SetupBuildEnvironment-Steps.yml are a dead duplicate consumed nowhere.)

The SetupBuildEnvironment step crashes first on the mono-build's short "2.0.0" build number,
but once that is guarded the build would crash again here. Apply the same length >= 10 guard so
the mono-build (Foundation versioned from $(WindowsAppSDKFormattedVersion)) doesn't throw.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant