Repository navigation
Add [self, nextMajor) upper bound on extensions' Microsoft.Testing.Platform dependency - #9730
Conversation
…atform dependency Extensions reference Microsoft.Testing.Platform via ProjectReference, which NuGet packs as an open-ended minimum-version dependency (e.g. 2.4.0 == [2.4.0, )). This lets an extension built against Testing Platform 2.x silently resolve a future breaking 3.0.0. Add a shared pack-time target under src/Platform that rewrites the packed Microsoft.Testing.Platform dependency to a [self, nextMajor) range (e.g. [2.4.0, 3.0.0)) as a safety net, since the extensions and the platform are versioned and ship in lockstep. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds an exclusive upper bound ([self, nextMajor)) to the packed Microsoft.Testing.Platform package dependency emitted by the in-repo MTP extensions (and Microsoft.Testing.Platform.MSBuild). By default, NuGet packs a ProjectReference as an open-ended minimum-version dependency (e.g. 2.4.0 == [2.4.0, )), which would let a 2.x-built extension silently resolve a future breaking 3.0.0. Since the extensions and the platform ship in lockstep, capping at the next major acts as a safety net. The change is confined to build/packaging infrastructure under src/Platform/ and does not touch product code.
Changes:
- Introduces
TestingPlatformNextMajorVersioninsrc/Platform/Directory.Build.props, computed as(major of TestingPlatformVersionPrefix) + 1.0.0(i.e.3.0.0today). - Adds a new
src/Platform/Directory.Build.targetswith a pack-time target (AfterTargets="_GetProjectReferenceVersions") that rewrites only theMicrosoft.Testing.Platformdependency entry to[self, nextMajor), preserving other metadata and skipping entries that are already a range. - The new targets file chains the repo-root
Directory.Build.targetsviaGetPathOfFileAboveso no existing build logic is dropped.
Show a summary per file
| File | Description |
|---|---|
src/Platform/Directory.Build.props |
Adds TestingPlatformNextMajorVersion property derived from the platform version's major component, used as the exclusive upper bound. |
src/Platform/Directory.Build.targets |
New file; chains the repo-root targets and adds a pack-time target that caps the emitted Microsoft.Testing.Platform dependency at the next major. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Medium
There was a problem hiding this comment.
Note
🤖 Automated review by GitHub Copilot. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.
Review Summary
Clean, well-documented MSBuild change that solves a real packaging safety concern. The implementation correctly caps the Microsoft.Testing.Platform dependency at the next major version boundary to prevent extensions from silently resolving a breaking future major.
Verification of Key Design Decisions
| Aspect | Assessment |
|---|---|
Version computation (Split('.')[0] + Add) |
✅ Correct — "2.4.0".Split('.')[0] → "2", Add("2", 1) → 3, final = 3.0.0 |
Import chain (GetPathOfFileAbove) |
✅ Correct — starts search from src/, finds repo-root Directory.Build.targets (no intermediate one at src/) |
Target hook (AfterTargets="_GetProjectReferenceVersions") |
✅ Correct hook point for modifying packed dependency versions |
Scope filter (%(Filename) == 'Microsoft.Testing.Platform') |
✅ Only touches the platform dependency; siblings (TrxReport.Abstractions, Telemetry, Platform.AI) unaffected |
Idempotency (StartsWith('[')) |
✅ Correctly detects if a range is already applied |
| Self-reference safety | ✅ Microsoft.Testing.Platform.csproj has no self-reference, so the inner condition never matches when it's the project being packed |
| Pre-release handling | ✅ Version like 2.4.0-dev is correctly wrapped to [2.4.0-dev, 3.0.0) — pre-release label stays in the lower bound |
Verdict Table
| Dimension | Status | Notes |
|---|---|---|
| Threading & Concurrency | ✅ N/A | MSBuild-only change |
| Security & IPC Contract Safety | ✅ N/A | No runtime code |
| Public API & Binary Compatibility | ✅ N/A | No public API surface; package dependency metadata only |
| Algorithmic Correctness | ✅ Pass | Version arithmetic and string manipulation are correct |
| Performance & Allocations | ✅ N/A | Runs only during pack, negligible overhead |
| Cross-TFM Compatibility | ✅ N/A | MSBuild targets are TFM-agnostic |
| Resource & IDisposable Management | ✅ N/A | No runtime code |
| Defensive Coding at Boundaries | ✅ Pass | Guard condition on TestingPlatformNextMajorVersion != ''; idempotency check prevents double-application |
| Correctness of Tests | No automated test verifies the nuspec output; manual verification provided in PR description is thorough | |
| Naming & Conventions | ✅ Pass | _AddTestingPlatformDependencyUpperBound follows private target naming convention |
| Code Duplication & DRY | ✅ Pass | Single definition point |
| Documentation & Comments | ✅ Pass | Thorough inline comments explain the "why" and the mechanism |
Minor Observations (non-blocking)
String.Copyobsolescence — cosmetic only, well-established MSBuild idiom (see inline comment).- Reliance on NuGet-internal targets — pragmatic and documented; a pack-output assertion test would harden against silent regressions (see inline comment).
Overall: LGTM — this is a well-crafted safety net with minimal risk and clear value.
…test - Replace the obsolete System.String::Copy idiom with System.String::new in the pack-time target condition (per review nit). - Add PackageDependencyUpperBoundTests acceptance test that inspects the produced .nuspec files and asserts every packed Microsoft.Testing.Platform dependency is a closed [min, nextMajor) range. This guards against silent regressions if the NuGet-internal _GetProjectReferenceVersions / _ProjectReferencesWithVersions targets are renamed and the upper-bound target stops firing (per review hardening suggestion). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Addressed the two review suggestions in 2bf3ac1:
|
🧪 Test quality grade — PR #9730
This advisory comment was generated automatically. Grades are heuristic
|
Summary
The Microsoft.Testing.Platform extensions (
src/Platform/Microsoft.Testing.Extensions.*, plusMicrosoft.Testing.Platform.MSBuild) referenceMicrosoft.Testing.Platformvia aProjectReference. When packed, NuGet emits that as an open-ended, minimum-version dependency — e.g.Microsoft.Testing.Platform version="2.4.0", which means[2.4.0, ).That open upper bound lets an extension built against Testing Platform 2.x silently resolve a future, potentially breaking 3.0.0. Since the extensions and the platform are versioned and ship in lockstep, this PR caps the packed dependency at the next major as a safety net:
Changes
src/Platform/Directory.Build.props— introducesTestingPlatformNextMajorVersion, computed as (major ofTestingPlatformVersionPrefix) + 1.0.0(i.e.3.0.0for the current 2.x line).src/Platform/Directory.Build.targets(new) — a pack-time target (AfterTargets="_GetProjectReferenceVersions") that rewrites the packedMicrosoft.Testing.Platformdependency's version to[self, nextMajor). It:Microsoft.Testing.Platformentry (sibling deps such asTrxReport.Abstractions,Telemetry,Platform.AIare left open-ended);exclude="Build,Analyzers");Directory.Build.targetsviaGetPathOfFileAboveso nothing is lost by introducing this file.Verification
Packed several projects locally and inspected the generated
.nuspecdependencies:Microsoft.Testing.Platformdep…Extensions.Retry[2.4.0-dev, 3.0.0)✅…Extensions.CrashDump[2.4.0-dev, 3.0.0)(siblingTrxReport.Abstractionsstays2.4.0-dev) ✅…Extensions.VSTestBridge[2.4.0-dev, 3.0.0)(siblingsTelemetry,TrxReport.Abstractionsstay open) ✅Microsoft.Testing.Platform.MSBuild[2.4.0-dev, 3.0.0)✅Microsoft.Testing.Platform…Extensions.AzureFoundryPlatform.AIonly — unaffected (out of scope) ✅Scope note: this targets the direct
Microsoft.Testing.Platformdependency specifically.Microsoft.Testing.Platform.AI(referenced only by AzureFoundry) is intentionally not bounded here.Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com