Skip to content

MSTest.Sdk: stop using VersionOverride so CPM with CentralPackageVersionOverrideEnabled=false works#7766

Merged
Evangelink merged 4 commits intomainfrom
copilot/fix-central-package-version-override
Apr 21, 2026
Merged

MSTest.Sdk: stop using VersionOverride so CPM with CentralPackageVersionOverrideEnabled=false works#7766
Evangelink merged 4 commits intomainfrom
copilot/fix-central-package-version-override

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 21, 2026

MSTest.Sdk's .targets set both Version and VersionOverride on every implicit PackageReference. Projects that enable Central Package Management with <CentralPackageVersionOverrideEnabled>false</CentralPackageVersionOverrideEnabled> then fail restore with NU1013 (see discussion #7440, issue #7441).

Changes

  • Branch on ManagePackageVersionsCentrally in every SDK .targets (VSTest, Runner/ClassicEngine, Runner/NativeAOT, Features/Aspire, Features/Playwright):
    • When CPM is off: emit Version as conditional nested metadata on the PackageReference.
    • When CPM is on: emit the PackageReference with no version metadata and add a matching PackageVersion item — works regardless of CentralPackageVersionOverrideEnabled.
  • Acceptance test: RunTests_With_CentralPackageManagement_Standalone previously didn't actually enable CPM. It now generates a Directory.Packages.props with ManagePackageVersionsCentrally=true and CentralPackageVersionOverrideEnabled=false, exercising the regressing scenario.
  • README: design notes rewritten to document the new pattern and explain why VersionOverride is no longer used; also fixed an IsImplictlyDefinedIsImplicitlyDefined typo.

Pattern applied

<PackageReference Include="MSTest.TestFramework" Sdk="MSTest">
  <Version Condition=" '$(ManagePackageVersionsCentrally)' != 'true' ">$(MSTestVersion)</Version>
</PackageReference>
<PackageVersion Include="MSTest.TestFramework" Version="$(MSTestVersion)"
                Condition=" '$(ManagePackageVersionsCentrally)' == 'true' " />

Compatibility note

Users who currently declare a PackageVersion for SDK-managed packages (e.g. MSTest.TestFramework, Microsoft.NET.Test.Sdk) in their own Directory.Packages.props will now get a duplicate-PackageVersion error and should remove those entries — overriding the SDK's defaults is done via the existing MSTestVersion/MicrosoftNETTestSdkVersion/etc. properties.

Copilot AI requested review from Copilot and removed request for Copilot April 21, 2026 07:50
…ersion injection

Agent-Logs-Url: https://github.com/microsoft/testfx/sessions/ef073c73-3140-4f65-b890-f3911b7f92b7

Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot April 21, 2026 08:00
Copilot AI requested review from Copilot and removed request for Copilot April 21, 2026 08:00
Copilot AI changed the title [WIP] Fix CentralPackageVersionOverrideEnabled with MSTest/Sdk MSTest.Sdk: stop using VersionOverride so CPM with CentralPackageVersionOverrideEnabled=false works Apr 21, 2026
Copilot AI requested a review from Evangelink April 21, 2026 08:02
@Evangelink Evangelink marked this pull request as ready for review April 21, 2026 09:05
Copilot AI review requested due to automatic review settings April 21, 2026 09:05
@Evangelink Evangelink enabled auto-merge April 21, 2026 09:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates MSTest.Sdk MSBuild targets to stop relying on VersionOverride so Central Package Management (CPM) restores succeed even when CentralPackageVersionOverrideEnabled=false.

Changes:

  • Replace VersionOverride-based implicit PackageReference versioning with a CPM-aware pattern: Version metadata when CPM is off, PackageVersion items when CPM is on.
  • Fix/strengthen the CPM acceptance test to actually enable CPM and set CentralPackageVersionOverrideEnabled=false.
  • Refresh MSTest.Sdk README design notes to document the new approach and correct an attribute name typo.
Show a summary per file
File Description
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/SdkTests.cs Updates acceptance test to enable CPM + strict override mode and validate restore/build still succeeds.
src/Package/MSTest.Sdk/Sdk/VSTest/VSTest.targets Switches implicit package versioning to CPM-aware Version/PackageVersion pattern.
src/Package/MSTest.Sdk/Sdk/Runner/NativeAOT.targets Applies the CPM-aware versioning pattern to NativeAOT runner dependencies and extensions.
src/Package/MSTest.Sdk/Sdk/Runner/ClassicEngine.targets Applies the CPM-aware versioning pattern to Classic runner dependencies and extensions.
src/Package/MSTest.Sdk/Sdk/Features/Playwright.targets Applies the CPM-aware versioning pattern for the Playwright feature package.
src/Package/MSTest.Sdk/Sdk/Features/Aspire.targets Applies the CPM-aware versioning pattern for the Aspire feature package.
src/Package/MSTest.Sdk/README.md Documents the new guidance/pattern and removes VersionOverride recommendation.

Copilot's findings

  • Files reviewed: 7/7 changed files
  • Comments generated: 2

Comment thread src/Package/MSTest.Sdk/README.md Outdated
Comment thread src/Package/MSTest.Sdk/README.md Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 21, 2026 09:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@Evangelink Evangelink merged commit 5792a26 into main Apr 21, 2026
14 of 15 checks passed
@Evangelink Evangelink deleted the copilot/fix-central-package-version-override branch April 21, 2026 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to use CentralPackageVersionOverrideEnabled == 'false' and MSTest/Sdk?

4 participants