Skills migrate-vstest-to-mtp
git clone https://github.com/dotnet/skills
T=$(mktemp -d) && git clone --depth=1 https://github.com/dotnet/skills "$T" && mkdir -p ~/.claude/skills && cp -r "$T/plugins/dotnet-test/skills/migrate-vstest-to-mtp" ~/.claude/skills/dotnet-skills-migrate-vstest-to-mtp && rm -rf "$T"
plugins/dotnet-test/skills/migrate-vstest-to-mtp/SKILL.mdVSTest -> Microsoft.Testing.Platform Migration
Migrate a .NET test solution from VSTest to Microsoft.Testing.Platform (MTP). The outcome is a solution where all test projects run on MTP,
dotnet test works correctly, and CI/CD pipelines are updated.
Important: Do not mix VSTest-based and MTP-based .NET test projects in the same solution or run configuration -- this is an unsupported scenario.
When to Use
- Switching from VSTest to Microsoft.Testing.Platform for any supported test framework
- Enabling
/dotnet run
/ direct executable execution for test projectsdotnet watch - Enabling Native AOT or trimmed test execution
- Replacing
withvstest.console.exe
on MTPdotnet test - Updating CI/CD pipelines from the VSTest task to the .NET Core CLI task
- Updating
arguments from VSTest syntax to MTP syntaxdotnet test
When Not to Use
- The project already runs on Microsoft.Testing.Platform -- migration is done
- Migrating between test frameworks (e.g., MSTest to xUnit.net) -- different effort entirely
- The project builds UWP or packaged WinUI test projects -- MTP does not support these yet
- The solution mixes .NET and non-.NET test adapters (e.g., JavaScript or C++ adapters) -- VSTest is required
- Upgrading MSTest versions -- use
ormigrate-mstest-v1v2-to-v3migrate-mstest-v3-to-v4
Inputs
| Input | Required | Description |
|---|---|---|
| Project or solution path | Yes | The , , or entry point containing test projects |
| Test framework | No | MSTest, NUnit, xUnit.net v2, or xUnit.net v3. Auto-detected from package references |
| .NET SDK version | No | Determines integration mode. Auto-detected via |
| CI/CD pipeline files | No | Paths to pipeline definitions that invoke or |
Workflow
Step 1: Assess the solution
- Identify the test framework for each test project -- see the
skill for the package-to-framework mapping. Key indicators:platform-detection- MSTest: References
orMSTest
, or usesMSTest.TestAdapter
(withMSTest.Sdk
not set to<IsTestApplication>
). Note:false
alone is a library dependency, not a test project.MSTest.TestFramework - NUnit: References
NUnit3TestAdapter - xUnit.net: References
andxunitxunit.runner.visualstudio
- MSTest: References
- Check the .NET SDK version (
) -- this determines howdotnet --version
integrates with MTPdotnet test - Check whether a
file exists at the solution or repo root -- all MTP properties should go there for consistencyDirectory.Build.props - Check for
usage in CI scripts or pipeline definitionsvstest.console.exe - Check for VSTest-specific
arguments in CI scripts:dotnet test
,--filter
,--logger
,--collect
,--settings--blame* - Run
to establish a baseline of test pass/fail countsdotnet test
Step 2: Set up Directory.Build.props
Critical: Always set MTP properties in
at the solution or repo root -- never per-project. This prevents inconsistent configuration where some projects use VSTest and others use MTP (an unsupported scenario). Note: MTP requires test projects to haveDirectory.Build.props. Only<OutputType>Exe</OutputType>sets this automatically. For all other setups (MSTest NuGet packages withMSTest.Sdk, NUnit withEnableMSTestRunner, xUnit.net withEnableNUnitRunner), you must setYTest.MTP.XUnit2explicitly -- either per-project or in<OutputType>Exe</OutputType>with a condition that targets only test projects.Directory.Build.props
Step 3: Enable the framework-specific MTP runner
Each framework has its own opt-in property. Add these in
Directory.Build.props for consistency.
MSTest
Option A -- MSTest NuGet packages (3.2.0+):
<PropertyGroup> <EnableMSTestRunner>true</EnableMSTestRunner> <OutputType>Exe</OutputType> </PropertyGroup>
Ensure the project references MSTest 3.2.0 or later. If the version is already 3.2.0+, no MSTest version upgrade is needed for MTP migration.
Option B -- MSTest.Sdk:
When using
MSTest.Sdk, MTP is enabled by default -- no EnableMSTestRunner or OutputType Exe property is needed (the SDK sets both automatically). The only action is: if the project has <UseVSTest>true</UseVSTest>, remove it. That property forces the project to use VSTest instead of MTP.
NUnit
Requires
NUnit3TestAdapter 5.0.0 or later.
- Update
to 5.0.0+:NUnit3TestAdapter
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
- Enable the NUnit runner:
<PropertyGroup> <EnableNUnitRunner>true</EnableNUnitRunner> <OutputType>Exe</OutputType> </PropertyGroup>
xUnit.net
Add a reference to
YTest.MTP.XUnit2 -- this package provides MTP support for xUnit.net v2 projects without requiring an upgrade to xunit.v3. You must also set OutputType to Exe:
<PackageReference Include="YTest.MTP.XUnit2" Version="0.4.0" />
<PropertyGroup> <OutputType>Exe</OutputType> </PropertyGroup>
Note:
preserves the VSTestYTest.MTP.XUnit2syntax, so no filter migration is needed for xUnit.net v2. It also supports--filterfor runsettings (xunit-specific configurations only),--settings, TRX reporting viaxunit.runner.json, and--report-trx.--treenode-filter
xUnit.net v3
xUnit.net v3 (
xunit.v3 package) has built-in MTP support. Enable it with:
<PropertyGroup> <UseMicrosoftTestingPlatformRunner>true</UseMicrosoftTestingPlatformRunner> </PropertyGroup>
Important: xUnit.net v3 on MTP does NOT support the VSTest
syntax. You must translate filters to xUnit.net v3's native filter options (see Step 5).--filter
Step 4: Configure dotnet test integration
The
dotnet test integration depends on the .NET SDK version.
.NET 10 SDK and later (recommended)
Use the native MTP mode by adding a
test section to global.json:
{ "sdk": { "version": "10.0.100" }, "test": { "runner": "Microsoft.Testing.Platform" } }
In this mode,
dotnet test arguments are passed directly -- for example, dotnet test --report-trx.
Important:
does not support trailing commas. Ensure the JSON is strictly valid.global.json
.NET 9 SDK and earlier
Use the VSTest mode of
dotnet test command to run MTP test projects by adding this property in Directory.Build.props:
<PropertyGroup> <TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport> </PropertyGroup>
Important: In this mode, you must use
to separate--build arguments from MTP arguments. For example:dotnet test.dotnet test --no-build -- --list-tests
Step 5: Update dotnet test command-line arguments
VSTest-specific arguments must be translated to MTP equivalents. Build-related arguments (
-c, -f, --no-build, --nologo, -v, etc.) are unchanged.
| VSTest argument | MTP equivalent | Notes |
|---|---|---|
| Not applicable | MTP does not use external adapter discovery |
| Not applicable | |
| | Requires NuGet package |
| | Requires CrashDump extension |
| | Requires NuGet package |
| | Requires HangDump extension |
| | Requires HangDump extension |
| | Per-extension arguments |
| | |
| | Same syntax for MSTest, NUnit, and xUnit.net v2 (with ). For xUnit.net v3, see filter migration below |
| | Requires NuGet package |
| | Same |
| | MSTest and NUnit still support |
| | Same |
| | Applicable only to MSTest and NUnit |
Filter migration
MSTest, NUnit, and xUnit.net v2 (with
): The VSTest YTest.MTP.XUnit2
--filter syntax is identical on both VSTest and MTP. No changes needed.
xUnit.net v3 (native MTP): xUnit.net v3 does NOT support the VSTest
--filter syntax on MTP. See the VSTest → MTP filter translation section in the filter-syntax skill for the complete translation table. Key translation example:
# VSTest dotnet test --filter "FullyQualifiedName~IntegrationTests&Category=Smoke" # xUnit.net v3 MTP -- using individual filters (AND behavior) dotnet test -- --filter-class *IntegrationTests* --filter-trait "Category=Smoke" # xUnit.net v3 MTP -- using query language (assembly/namespace/class/method[trait]) dotnet test -- --filter-query "/*/*/*IntegrationTests*/*[Category=Smoke]"
Note: When combining
and--filter-class, both conditions must match (AND behavior). For complex expressions, use--filter-traitwith the path-segment syntax. See the xUnit.net query filter language docs for full reference.--filter-query
Step 6: Install MTP extension packages (if needed)
If CI scripts use TRX reporting, crash dumps, or hang dumps, add the corresponding NuGet packages:
<!-- TRX report generation (replaces --logger trx) --> <PackageReference Include="Microsoft.Testing.Extensions.TrxReport" Version="1.6.2" /> <!-- Crash dump collection (replaces --blame-crash) --> <PackageReference Include="Microsoft.Testing.Extensions.CrashDump" Version="1.6.2" /> <!-- Hang dump collection (replaces --blame-hang) --> <PackageReference Include="Microsoft.Testing.Extensions.HangDump" Version="1.6.2" /> <!-- Code coverage (replaces --collect "Code Coverage") --> <PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="17.13.0" />
Step 7: Update CI/CD pipelines
Azure DevOps
If using the VSTest task (
): Replace with the .NET Core CLI task (VSTest@3
DotNetCoreCLI@2):
# Before (VSTest task) - task: VSTest@3 inputs: testAssemblyVer2: '**/*Tests.dll' runSettingsFile: 'test.runsettings' # After (.NET Core CLI task) - task: DotNetCoreCLI@2 displayName: Run tests inputs: command: 'test' arguments: '--no-build --configuration Release'
If already using DotNetCoreCLI@2: Update arguments per Step 5 translations. Remember the
-- separator on .NET 9 and earlier:
- task: DotNetCoreCLI@2 displayName: Run tests inputs: command: 'test' arguments: '--no-build -- --report-trx --results-directory $(Agent.TempDirectory)'
GitHub Actions
Update
dotnet test invocations in workflow files with the same argument translations from Step 5.
Replace vstest.console.exe
If any script invokes
vstest.console.exe directly, replace it with dotnet test. The test projects are now executables and can also be run directly.
Step 8: Handle behavioral differences
Zero tests exit code
VSTest silently succeeds when zero tests are discovered. MTP fails with exit code 8. Options:
- Pass
when running tests--ignore-exit-code 8 - Add to
:Directory.Build.props
<PropertyGroup> <TestingPlatformCommandLineArguments>$(TestingPlatformCommandLineArguments) --ignore-exit-code 8</TestingPlatformCommandLineArguments> </PropertyGroup>
- Use environment variable:
TESTINGPLATFORM_EXITCODE_IGNORE=8
Step 9: Remove VSTest-only packages (optional)
Once migration is complete and verified, remove packages that are only needed for VSTest:
-- not needed for MTP (MSTest.Sdk v4 already omits it by default)Microsoft.NET.Test.Sdk
-- only needed for VSTest discovery of xUnit.net (not needed when usingxunit.runner.visualstudio
)YTest.MTP.XUnit2
VSTest-only features -- the adapter is still needed but only for the MTP runnerNUnit3TestAdapter
Note: If you need to maintain VSTest compatibility during a transition period, keep these packages.
Step 10: Verify
- Run
-- confirm zero errorsdotnet build - Run
-- confirm all tests passdotnet test - Compare test pass/fail counts to the pre-migration baseline
- Run the test executable directly (e.g.,
) -- confirm it works./bin/Debug/net8.0/MyTests.exe - Verify CI pipeline produces the expected test result artifacts (TRX files, code coverage, crash dumps)
- Test that Test Explorer in Visual Studio (17.14+) or VS Code discovers and runs tests
Validation
- All test projects use MTP runner (no VSTest-only configuration remains)
-
completes with zero errorsdotnet build -
passes all tests and test counts match pre-migration baselinedotnet test - Test executable runs directly (e.g.,
)./bin/Debug/net8.0/MyTests.exe - CI pipeline produces expected test result artifacts (TRX files, code coverage, crash dumps)
- Test Explorer in Visual Studio or VS Code discovers and runs tests
- No
invocations remain in CI scriptsvstest.console.exe -
is set for all non-MSTest.Sdk test projects<OutputType>Exe</OutputType>
Common Pitfalls
| Pitfall | Solution |
|---|---|
| Mixing VSTest and MTP projects in the same solution | Migrate all test projects together -- mixed mode is unsupported |
arguments ignored on .NET 9 and earlier | Use to separate build args from MTP args: |
| Exit code 8 on CI without failures | MTP fails when zero tests run; use or fix test discovery |
| MSTest.Sdk v4 + vstest.console no longer works | MSTest.Sdk v4 no longer adds -- add it explicitly or switch to |
Missing | Required for all setups except MSTest.Sdk (which sets it automatically) |
Next Steps
- Use
for running tests on the new MTP platformrun-tests - Use
for iterative test fixing with hot reload on MTPmtp-hot-reload