Skip to content

Fix duplicate PackageReferences for MSTest packages during project conversion#318

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-317
Draft

Fix duplicate PackageReferences for MSTest packages during project conversion#318
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-317

Conversation

Copy link
Contributor

Copilot AI commented Jul 11, 2025

Problem

When converting legacy project files that already contain MSTest packages (MSTest.TestAdapter and MSTest.TestFramework), the transformation was creating duplicate PackageReferences. This happened because the transformation only checked for the existence of Microsoft.NET.Test.Sdk before adding all test packages, but didn't check if individual MSTest packages already existed.

Example of the Issue

Before the fix, a project with:

<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />

Would end up with duplicates after conversion:

<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />

Solution

Modified TestProjectPackageReferenceTransformation to:

  1. Check for each test package individually before adding them
  2. Only add packages that don't already exist in the project
  3. Maintain backward compatibility by still skipping all packages if Microsoft.NET.Test.Sdk already exists

Changes Made

  • Enhanced duplicate detection: The transformation now checks for existing packages individually using existingPackageReferences.Any(existingRef => existingRef.Id == testRef.Id)
  • Selective package addition: Only missing packages are added to avoid duplicates
  • Preserved backward compatibility: Projects with existing Microsoft.NET.Test.Sdk continue to work as before

Test Coverage

Added comprehensive test cases covering:

  • Projects with existing MSTest packages (no duplicates created)
  • Projects with partial MSTest packages (only missing ones added)
  • Projects with existing Test SDK (maintains current behavior)

Fixes #317.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

…missing packages individually

Co-authored-by: mungojam <3154635+mungojam@users.noreply.github.com>
Copilot AI changed the title [WIP] Duplicate PackageReferences are create for MsTest Fix duplicate PackageReferences for MSTest packages during project conversion Jul 11, 2025
Copilot AI requested a review from mungojam July 11, 2025 20:54
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.

Duplicate PackageReferences are create for MsTest

2 participants