Use MSBuild SHA instead of VMR SHA but keep both
Fixes #13832
Context
When MSBuild is built in the VMR (dotnet/dotnet), the commit embedded in the assembly
InformationalVersion (via SourceLink's SourceRevisionId) is the VMR commit, not the
dotnet/msbuild commit. That commit surfaces in MSBuild's startup banner and in everything derived
from ProjectCollection.DisplayVersion (the $(MSBuildSemanticVersion) property and build
telemetry), so it can't be traced back to MSBuild source.
The VMR already passes the original product-repo commit to the per-repo build as
RepoOriginalSourceRevisionId. This change surfaces that commit as the primary SHA and keeps the
VMR commit as secondary info.
Changes Made
src/Framework/Microsoft.Build.Framework.csproj: whenRepoOriginalSourceRevisionIdis set (VMR builds), emit[assembly: AssemblyMetadata("RepoOriginalSourceRevisionId", ...)]on the Framework assembly.ProjectCollection.DisplayVersion: prefer the MSBuild commit fromRepoOriginalSourceRevisionIdwhen present; otherwise fall back to the existing behavior. This fixes the banner,$(MSBuildSemanticVersion), and telemetry in one place.- Startup banner (
XMake.cs): when the VMR commit differs from the MSBuild commit (i.e. real VMR builds), show it as secondary —MSBuild version <ver>+<msbuildSha> (VMR <vmrSha>) for <fw>. Added theMSBuildVersionMessageWithVmrresource string.
Testing
- Standalone/dev build: banner,
$(MSBuildSemanticVersion), and telemetry are byte-for-byte unchanged (noRepoOriginalSourceRevisionId=> no metadata => identical fallback path). - Simulated VMR build (
/p:RepoOriginalSourceRevisionId=<sha>):- Banner:
MSBuild version 18.8.0-dev-26316-01+aaaaaaaaa (VMR 4ea821593) for .NET Framework $(MSBuildSemanticVersion)reports the MSBuild commit (primary).
- Banner:
- Existing version tests pass: only the SHA content changes; the SemVer structure and the
Major.Minor.Buildnumeric prefix are unchanged.
Notes
InformationalVersionintentionally keeps the VMR commit — it records how the binary was physically built, so NuGet/package metadata is unchanged.DisplayVersionis the user-facing "product" version and now leads with the MSBuild commit.- The
-versionswitch is unchanged (it prints the 4-part file version, no SHA). - Follow-up (separate dotnet/sdk PR): the same pattern is applied to the SDK's own
Commit:line indotnet --info; theMSBuild version:line there already readsProjectCollection.DisplayVersion, so it picks this up automatically once the MSBuild bump flows in.
Expert review finding (major): this new VMR-specific path needs regression coverage.
ProjectCollection.DisplayVersion now prefers RepoOriginalSourceRevisionId, and XMake can print MSBuildVersionMessageWithVmr when that differs from the VMR SHA in InformationalVersion. Existing coverage appears to keep asserting only the non-VMR banner shape, so it would not catch regressions in the intended VMR behavior or a banner mismatch when running against VMR-stamped binaries.
Could you add targeted coverage that simulates the VMR case and verifies:
ProjectCollection.DisplayVersionuses the truncatedRepoOriginalSourceRevisionId;- the startup banner includes
(VMR <truncated-vmr-sha>); - the existing non-VMR banner remains unchanged?
@AlesProkop I believe you opened pr in VRM for this?
@AlesProkop I believe you opened pr in VRM for this?
@OvesN Yes, closing this one, as there is a PR in the VMR