Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Migrate MSTest v1 or v2 test projects to MSTest v3. Use when the user asks to upgrade MSTest and the project has QualityTools assembly references, MSTest.TestFramework/TestAdapter 1.x-2.x, .testsettings, or migration errors after changing those packages to 3.x. USE FOR: upgrading from MSTest v1 assembly references (Microsoft.VisualStudio.QualityTools.UnitTestFramework) or MSTest v2 NuGet (MSTest.TestFramework 1.x-2.x) to MSTest v3, fixing assertion overload errors (AreEqual/AreNotEqual), updatin
.claude/skills/managedcode-migrate-mstest-v1v2-to-v3/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-04 | ✗→✓ | ▲ Improved | 1589% | 0% |
| case-07 | ✗→✓ | ▲ Improved | 97% | 0% |
| case-08 | ✗→✓ | ▲ Improved | 46% | 0% |
| case-13 | ✗→✓ | ▲ Improved | 101% | 0% |
| case-15 | ✗→✓ | ▲ Improved | 117% | 0% |
Migrate a test project from MSTest v1 (assembly references) or MSTest v2 (NuGet 1.x-2.x) to MSTest v3. MSTest v3 is not binary compatible with v1/v2 -- libraries compiled against v1/v2 must be recompiled.
Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll (MSTest v1)MSTest.TestFramework / MSTest.TestAdapter NuGet 1.x or 2.x.testsettings with .runsettingsmigrate-mstest-v3-to-v4Check package versions before any edit. If all MSTest references are already 3.x and no v1/v2-to-v3 error is reported, state that migration is complete and make no changes. Do not consolidate working v3 packages into the metapackage. Run the existing tests only if verification was requested. This overrides all steps below.
| Input | Required | Description | |-------|----------|-------------| | Project or solution path | Yes | The .csproj, .sln, or .slnx entry point containing MSTest test projects | | Build command | No | How to build (e.g., dotnet build, a repo build script). Auto-detect if not provided | | Test command | No | How to run tests (e.g., dotnet test). Auto-detect if not provided |
MSTest v3 introduces these breaking changes from v1/v2. Address only the ones relevant to the project:
| Breaking Change | Impact | Fix | |---|---|---| | Assert.AreEqual(object, object) overload removed | Compile error on untyped assertions | Add generic type: Assert.AreEqual<T>(expected, actual). Same for AreNotEqual, AreSame, AreNotSame | | DataRow strict type matching | Runtime/compile errors when argument types don't match parameter types exactly | Change literals to exact types: 1 for int, 1L for long, 1.0f for float | | DataRow max 16 constructor parameters (early v3) | Compile error if >16 args; fixed in later v3 versions | Update to latest 3.x, or refactor test / wrap extra params in array | | .testsettings / <LegacySettings> no longer supported | Settings silently ignored | Delete .testsettings, create .runsettings with equivalent config | | Timeout behavior unified across .NET Core / Framework | Tests with [Timeout] may behave differently | Verify timeout values; adjust if needed | | Dropped target frameworks: .NET 5, .NET Fx < 4.6.2, netstandard1.0, UWP < 16299, WinUI < 18362 | Build error | Update TFM: .NET 5 -> net8.0 (LTS) or net6.0+, netfx -> net462+, netstandard1.0 -> netstandard2.0. Note: net6.0, net8.0, net9.0 are all supported | | Not binary compatible with v1/v2 | Libraries compiled against v1/v2 must be recompiled | Recompile all dependencies against v3 | | Test ID generation changed | Playlists, filters, or CI history keyed by test ID may reset | Re-baseline IDs and verify affected filters | | TargetInvocationException is unwrapped | Tests or infrastructure expecting the wrapper observe the inner exception | Update exception handling to expect the underlying exception | | Initialization/cleanup messages now attach to test results | The first/last test output may gain lifecycle messages that were previously absent | Update log processing and inspect the first/last test results | | Deployment directory behavior is unified across TFMs | Tests with hard-coded deployment paths may fail | Use TestContext.DeploymentDirectory or deployed-item paths instead of assumptions | | Nullable annotations were added | Nullable-enabled projects may gain warnings | Fix the warnings without suppressing unrelated diagnostics |
DataRow with its method signature. Mismatches can build with only MSTEST0014 and fail during test execution. Preserve the method contract and normally fix the literal (1L -> 1 for int), then run the affected tests..testsettings, put all MSTest settings under one <MSTest> element, map requested deployment, per-test timeout, data collector, and other active configuration, and do not add a session-wide timeout. Do not walk through unrelated breaking changes.Both paths converge at Step 3 -- the same v3 packages and breaking changes apply regardless of starting version.
Microsoft.VisualStudio.QualityTools.UnitTestFramework in project references -> MSTest v1MSTest.TestFramework and MSTest.TestAdapter package versions -> v1 if 1.x, v2 if 2.xIf the project uses MSTest v1 via assembly references:
Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll<Reference> element from the .csprojUse one package model; do not leave duplicate framework/adapter references.
Default -- install the MSTest metapackage:
Remove individual MSTest.TestFramework and MSTest.TestAdapter package references and replace with the unified MSTest metapackage:
xml<PackageReference Include="MSTest" Version="3.8.0" />
Keep Microsoft.NET.Test.Sdk when the project remains on VSTest, but update it to a version compatible with the selected MSTest release. For example, MSTest 3.8.0 requires Microsoft.NET.Test.Sdk 17.13.0 or later; leaving an older explicit version causes NU1605. If package versions are centrally managed, update Directory.Packages.props rather than adding inline versions.
Use MSTest.Sdk only when the user requests it or the repository already standardizes on it (SDK-style projects only):
Change <Project Sdk="Microsoft.NET.Sdk"> to <Project Sdk="MSTest.Sdk/3.8.0">. MSTest.Sdk automatically provides the MSTest framework, adapter, and analyzers.
> Important: MSTest.Sdk defaults to Microsoft.Testing.Platform (MTP). When preserving VSTest, set <UseVSTest>true</UseVSTest>; the SDK then supplies the required Microsoft.NET.Test.Sdk reference. Do not switch runners merely as a side effect of the framework upgrade.
When switching to MSTest.Sdk, remove these (SDK provides them automatically):
MSTest, MSTest.TestFramework, MSTest.TestAdapter, MSTest.Analyzers, Microsoft.NET.Test.Sdk<EnableMSTestRunner>, <OutputType>Exe</OutputType>, <IsPackable>false</IsPackable>, <IsTestProject>true</IsTestProject>MSTest v3 supports .NET 6+, .NET Core 3.1, .NET Framework 4.6.2+, .NET Standard 2.0, UWP 16299+, and WinUI 18362+. .NET Core 3.1 is end-of-life but remains supported by MSTest v3; preserve it during this framework-only migration and recommend a separate runtime upgrade. If the project targets a framework version dropped by MSTest v3, update to a supported one:
| Dropped | Recommended replacement | |---------|------------------------| | .NET 5 | .NET 8.0 (current LTS) or .NET 6+ | | .NET Framework < 4.6.2 | .NET Framework 4.6.2 | | .NET Standard 1.0 | .NET Standard 2.0 | | UWP < 16299 | UWP 16299 | | WinUI < 18362 | WinUI 18362 |
> Note: .NET 6, .NET 8, and .NET 9 are all supported by MSTest v3. Do not change TFMs that are already supported.
Search the supplied files first and fix only breaking changes that are present. A successful build does not prove compatibility; some failures surface only as analyzer warnings or during test execution.
Assertion overloads -- MSTest v3 removed Assert.AreEqual(object, object) and Assert.AreNotEqual(object, object). Add explicit generic type parameters:
csharp// Before (v1/v2) // After (v3) Assert.AreEqual(expected, actual); -> Assert.AreEqual<MyType>(expected, actual); Assert.AreNotEqual(a, b); -> Assert.AreNotEqual<MyType>(a, b); Assert.AreSame(expected, actual); -> Assert.AreSame<MyType>(expected, actual);
DataRow strict type matching -- argument types must exactly match parameter types. Implicit conversions that worked in v2 fail in v3:
csharp// Error: 1L (long) won't convert to int parameter -> fix: use 1 (int) // Error: 1.0 (double) won't convert to float parameter -> fix: use 1.0f (float)
Preserve method parameter types unless independently wrong. dotnet build may succeed with MSTEST0014; run the test to prove each row binds and executes.
Timeout behavior -- unified across .NET Core and .NET Framework. Verify [Timeout] values still work.
The .testsettings file and <LegacySettings> are no longer supported in MSTest v3. Delete the .testsettings file and create a .runsettings file -- do not keep both. Consolidate all MSTest configuration under one <MSTest> element; do not create an <MSTestV2> section.
Key mappings:
| .testsettings | .runsettings equivalent | |---|---| | TestTimeout property | <MSTest><TestTimeout>30000</TestTimeout></MSTest> | | Deployment config | <MSTest><DeploymentEnabled>true</DeploymentEnabled></MSTest> or remove | | Assembly resolution settings | Remove -- not needed in modern .NET | | Data collectors | <DataCollectionRunSettings><DataCollectors> section |
> Important: Map timeout to <MSTest><TestTimeout> (per-test), not <TestSessionTimeout> (session-wide). Remove <LegacySettings> entirely.
dotnet test builds by default; run a separate build only to isolate a compilation failure..testsettings, or <LegacySettings> remains.dotnet test) -- compare pass/fail counts to pre-migration baseline.testsettings replaced with .runsettings (if applicable)After v3 migration, use migrate-mstest-v3-to-v4 for MSTest v4.
| Pitfall | Solution | |---------|----------| | Non-MSTest.Sdk VSTest project missing Microsoft.NET.Test.Sdk | Add the package reference for VSTest discovery | | MSTest.Sdk tests not found by vstest.console | Set <UseVSTest>true</UseVSTest>; MSTest.Sdk then supplies Microsoft.NET.Test.Sdk |
Other measured skills in the registry, with their headline benchmark lift.