MSTest v3 -> v4 Migration
Migrate a test project from MSTest v3 to MSTest v4. The outcome is a project using MSTest v4 that builds cleanly, passes tests, and accounts for every source-incompatible and behavioral change. MSTest v4 is not binary compatible with MSTest v3 -- any library compiled against v3 must be recompiled against v4.
First Action
Inspect the supplied project and source before searching the web or answering
from memory. Classify the request as a focused source fix, runtime behavior
change, CI discovery issue, compatibility question, or full migration, then
follow the matching row below. A clean compile does not exclude this skill:
discovery failures, TestContext lifecycle exceptions, and test-history
changes are runtime migration failures.
When to Use
- Upgrading
MSTest.TestFramework, MSTest.TestAdapter, or MSTest metapackage from 3.x to 4.x
- Upgrading
MSTest.Sdk from 3.x to 4.x
- Fixing build errors after updating to MSTest v4 packages
- Resolving behavioral changes in test execution after upgrading to MSTest v4
- Updating custom
TestMethodAttribute or ConditionBaseAttribute implementations for v4
When Not to Use
- The project already uses MSTest v4 with verified discovery and test execution, and has no remaining migration-related issues
- Upgrading from MSTest v1 or v2 -- use
migrate-mstest-v1v2-to-v3 first, then return here
- The project does not use MSTest
- Migrating between test frameworks (e.g., MSTest to xUnit or NUnit)
Inputs
| Input |
Required |
Description |
| Project or solution path |
No |
The .csproj, .sln, or .slnx entry point containing MSTest test projects. Discover it yourself by globbing the working directory; ask only when nothing is found or the choice is genuinely ambiguous |
| 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 |
Decisions That Change the Result
| Detected request or state |
Required action |
| Files are supplied in the current workspace |
Search there and open the literal returned paths. The skill directory is not the project directory. If one tool rejects a valid path, retry with another available reader/editor; do not ask the user for a path you can discover. |
| User asks to apply changes to supplied files: "fix my project/files", "please update this source", "make the changes", or "then build and run" |
Edit every affected occurrence. Run the narrowest meaningful build/test command against the actual package version; skill activation is not a reason to stop at advice. |
| User asks "what should I expect?", "how do I fix these changes?", for compatibility advice, or for a plan |
Answer directly from the actual project state even when source is visible. Keep a single-symptom answer focused; include only adjacent risks that change the decision. |
| Unsupported TFM in a full migration |
Update the TFM first, then update MSTest packages, then fix source breaks. Do not bury this order in a release-note inventory. |
Custom TestMethodAttribute subclass |
Treat ExecuteAsync, CallerInfo propagation, display-name handling, and the subclass's retry/result semantics as one coupled migration. Fix the actual class, not a placeholder example. |
MSTest.Sdk v4 source/API errors (ManagedType, TestTimeout, Contains) |
Give the exact source replacements, then add the adjacent runner warning: MTP mode no longer supplies Microsoft.NET.Test.Sdk; add it only if VSTest discovery is still required. |
MSTest.Sdk v4 plus vstest.console |
MTP mode no longer includes Microsoft.NET.Test.Sdk in v4. Add it to retain transitional VSTest discovery while keeping MTP, opt into UseVSTest, or migrate CI to dotnet test. Native MTP requires every project/TFM governed by global.json to support it (4.5). |
Response Guidelines
- Always identify the current version first: Before recommending any migration steps, explicitly state the current MSTest version detected in the project (e.g., "Your project uses MSTest v3 (3.8.0)"). This confirms you've read the project files and grounds the migration advice.
- Resolve, do not assume, the target version: When the user asks for "latest", query the project's configured package source and select the latest stable MSTest v4 version available at execution time. Never copy the example version from this skill into the result without checking it. Keep all MSTest packages on the same resolved version.
- Focused fix requests: Address only matching Step 3 changes with concrete code using the user's types and names. Edit only when a source change is requested; "how do I fix these?" remains an answer request. A green v3 build does not verify v4: update packages when requested or state that limitation. For custom attributes, show the full fixed class with CallerInfo propagation and preserved retry/result semantics. Mention relevant analyzers (e.g., MSTEST0006 for ExpectedException). For
MSTest.Sdk, explain whether losing the Microsoft.NET.Test.Sdk reference affects the visible runner. Skip the full migration workflow.
- "What to expect" questions (user asks about breaking changes before upgrading): Present ALL major breaking changes from the Step 3 quick-lookup table -- not just the ones visible in the current code. For each, provide a one-line fix summary. Also mention key behavioral changes from Step 4 (especially TestCase.Id history impact and TreatDiscoveryWarningsAsErrors default). If project code is available, highlight which changes apply directly.
- Before-upgrade analyzer guidance: Recommend fixing MSTEST0006, MSTEST0039, and MSTEST0053 warnings while still on v3 because those analyzers are not available in v4. Mention MSTEST0034 when class-cleanup timing is relevant. For
TestMethodAttribute constructor issues, include MSTEST0056 for display-name arguments and MSTEST0057 for custom attributes that fail to propagate caller info.
- Full migration requests (user wants complete migration): Follow the complete workflow below.
- Behavioral/runtime symptoms: Match symptoms to Step 4 and give targeted advice, including adjacent behavioral risks. Skip source-breaking changes unless there are also build errors.
- CI/test-discovery issues: Match the failure first: resolve loader errors (4.7) rather than suppressing warnings (4.4). For
MSTest.Sdk v4 plus failing vstest.console discovery, explain the missing Microsoft.NET.Test.Sdk reference (4.5) and all three paths: add it while preserving MTP, set UseVSTest, or switch CI to MTP-native dotnet test. Skip the full migration workflow.
- Explanatory questions (user asks "is this a known change?", "what else should I watch out for?"): Explain the relevant changes and advise. Mention related changes the user might encounter next. Do not prescribe a full migration procedure.
- Result proof: End implementation work with the detected v3 version, resolved v4 version, runner choice, files changed, and actual build/test counts. Never report a build, VSTest compatibility, discovery, or passing tests from inference.
Workflow
Commit strategy: Do not create commits unless the user asks. Keep package,
source, and behavioral changes logically separable in the diff, but finish and
verify the requested migration.
Step 1: Assess the project
- Identify the current MSTest version by checking package references for
MSTest, MSTest.TestFramework, MSTest.TestAdapter, or MSTest.Sdk in .csproj, Directory.Build.props, or Directory.Packages.props.
- Confirm the starting state: v3 for an upgrade, or v4 for a post-upgrade fix. If already on v4, skip Step 2 unless package changes are needed for the reported issue. If on v1 or v2, use
migrate-mstest-v1v2-to-v3 first.
- Check target framework(s) -- MSTest v4 drops support for .NET Core 3.1 through .NET 7. Supported target frameworks are: net8.0, net9.0, net462 (.NET Framework 4.6.2+), uap10.0.16299 (UWP), net9.0-windows10.0.17763.0 (modern UWP), and net8.0-windows10.0.18362.0 (WinUI).
- Check for custom
TestMethodAttribute subclasses and uses of DataTestMethodAttribute, STATestMethodAttribute, and UITestMethodAttribute constructors -- these require changes in v4.
- Check for usages of
ExpectedExceptionAttribute -- removed in v4 (deprecated since v3 with analyzer MSTEST0006).
- Check for usages of
Assert.ThrowsException (deprecated) -- removed in v4.
- Search for removed
TestContext properties, changed ITestMethod members, removed cleanup settings, and custom data-source interfaces or overrides listed in Step 3.
- If code or tools reference MSTest assemblies by name/version or the VSTest executor URI, inventory those references; check whether the test adapter relies on its former
netstandard2.0 asset.
- Run a clean build to establish a baseline of existing errors/warnings.
Step 2: Update packages to MSTest v4
First resolve the latest stable v4 version from the configured package source. Pin that exact
version consistently in the metapackage, individual packages, MSTest.Sdk, and central package
management.
- For the
MSTest metapackage, update its PackageReference to the resolved exact version.
- For individual packages, update
MSTest.TestFramework and MSTest.TestAdapter to that same version.
- For
MSTest.Sdk, update the SDK version in the project or global.json pin to that same version.
Run dotnet restore, then dotnet build. Collect all errors for Step 3.
Step 3: Resolve source breaking changes
Work through compilation errors systematically. Use this quick-lookup table to identify all applicable changes, then apply each fix: