msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

Use MSBuild SHA instead of VMR SHA but keep both

Open AlesProkop opened this issue 5 months ago • 1 comments

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: when RepoOriginalSourceRevisionId is set (VMR builds), emit [assembly: AssemblyMetadata("RepoOriginalSourceRevisionId", ...)] on the Framework assembly.
  • ProjectCollection.DisplayVersion: prefer the MSBuild commit from RepoOriginalSourceRevisionId when 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 the MSBuildVersionMessageWithVmr resource string.

Testing

  • Standalone/dev build: banner, $(MSBuildSemanticVersion), and telemetry are byte-for-byte unchanged (no RepoOriginalSourceRevisionId => 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).
  • Existing version tests pass: only the SHA content changes; the SemVer structure and the Major.Minor.Build numeric prefix are unchanged.

Notes

  • InformationalVersion intentionally keeps the VMR commit — it records how the binary was physically built, so NuGet/package metadata is unchanged. DisplayVersion is the user-facing "product" version and now leads with the MSBuild commit.
  • The -version switch 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 in dotnet --info; the MSBuild version: line there already reads ProjectCollection.DisplayVersion, so it picks this up automatically once the MSBuild bump flows in.

AlesProkop avatar Jun 16 '26 07:06 AlesProkop

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:

  1. ProjectCollection.DisplayVersion uses the truncated RepoOriginalSourceRevisionId;
  2. the startup banner includes (VMR <truncated-vmr-sha>);
  3. the existing non-VMR banner remains unchanged?

AlesProkop avatar Jun 16 '26 08:06 AlesProkop

@AlesProkop I believe you opened pr in VRM for this?

OvesN avatar Jul 07 '26 08:07 OvesN

@AlesProkop I believe you opened pr in VRM for this?

@OvesN Yes, closing this one, as there is a PR in the VMR

AlesProkop avatar Jul 07 '26 10:07 AlesProkop