[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M76SD0M48A9PP8BA4AT4WJJW":3,"skill-same:01M76SD0M48A9PP8BA4AT4WJJW":46},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":25,"commitSha":26,"skillDirectory":27,"forksCount":14,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":30,"ownerDescription":6,"updatedAt":31,"install":32,"resources":45},"01M76SD0M48A9PP8BA4AT4WJJW","migrate-mstest-v3-to-v4",null,"Fix build errors and breaking changes after upgrading MSTest from v3 to v4, or plan a complete MSTest v3-to-v4 migration. Use when user says \"upgrade to MSTest v4\", \"MSTest 4 migration\", \"MSTest v4 breaking changes\", \"tests don't compile after upgrading MSTest\", or has errors CS0507, CS0103, CS1061, CS1615 after updating MSTest packages from 3.x to 4.x. USE FOR: Execute to ExecuteAsync, CallerInfo constructor on TestMethodAttribute, sealed custom attributes, ClassCleanupBehavior removal, TestContext.Properties Contains to ContainsKey, Assert.ThrowsException to ThrowsExactly, Assert.IsInstanceOfType out parameter removal, ExpectedExceptionAttribute removal, TestTimeout enum removal, [TestMethod(\"name\")] to DisplayName syntax, TreatDiscoveryWarningsAsErrors, TestContext.TestName in ClassInitialize, MSTest.Sdk MTP changes, dropped TFMs (net6.0\u002Fnet7.0 to net8.0+). DO NOT USE FOR: migrating from MSTest v1\u002Fv2 to v3 (use migrate-mstest-v1v2-to-v3 first), migrating between test frameworks, or general .NET upgrades.","weiflycc-cmd\u002Fskills","weiflycc-cmd","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F250846518?v=4","01M756C4PFGZJWKK04WFB9S5XF","威飛工作室","01M756C4QJJ66QDXN2RN6SXY87",0,"MIT","https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd\u002Fskills\u002Fblob\u002Fmain\u002Fplugins\u002Fdotnet-test\u002Fskills\u002Fmigrate-mstest-v3-to-v4\u002FSKILL.md",[],[],"2026-11-12 13:55:43",false,"---\nname: migrate-mstest-v3-to-v4\ndescription: >\n  Fix build errors and breaking changes after upgrading MSTest from v3 to v4,\n  or plan a complete MSTest v3-to-v4 migration. Use when user says \"upgrade to\n  MSTest v4\", \"MSTest 4 migration\", \"MSTest v4 breaking changes\", \"tests don't\n  compile after upgrading MSTest\", or has errors CS0507, CS0103, CS1061, CS1615 after updating MSTest packages from 3.x to 4.x.\n  USE FOR: Execute to ExecuteAsync, CallerInfo constructor on TestMethodAttribute,\n  sealed custom attributes, ClassCleanupBehavior removal, TestContext.Properties\n  Contains to ContainsKey, Assert.ThrowsException to ThrowsExactly,\n  Assert.IsInstanceOfType out parameter removal, ExpectedExceptionAttribute\n  removal, TestTimeout enum removal, [TestMethod(\"name\")] to DisplayName syntax,\n  TreatDiscoveryWarningsAsErrors, TestContext.TestName in ClassInitialize,\n  MSTest.Sdk MTP changes, dropped TFMs (net6.0\u002Fnet7.0 to net8.0+).\n  DO NOT USE FOR: migrating from MSTest v1\u002Fv2 to v3 (use migrate-mstest-v1v2-to-v3\n  first), migrating between test frameworks, or general .NET upgrades.\nlicense: MIT\n---\n\n# MSTest v3 -> v4 Migration\n\nMigrate 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.\n\n## When to Use\n\n- Upgrading `MSTest.TestFramework`, `MSTest.TestAdapter`, or `MSTest` metapackage from 3.x to 4.x\n- Upgrading `MSTest.Sdk` from 3.x to 4.x\n- Fixing build errors after updating to MSTest v4 packages\n- Resolving behavioral changes in test execution after upgrading to MSTest v4\n- Updating custom `TestMethodAttribute` or `ConditionBaseAttribute` implementations for v4\n\n## When Not to Use\n\n- The project already uses MSTest v4 and builds cleanly -- migration is done\n- Upgrading from MSTest v1 or v2 -- use `migrate-mstest-v1v2-to-v3` first, then return here\n- The project does not use MSTest\n- Migrating between test frameworks (e.g., MSTest to xUnit or NUnit)\n\n## Inputs\n\n| Input | Required | Description |\n|-------|----------|-------------|\n| Project or solution path | Yes | The `.csproj`, `.sln`, or `.slnx` entry point containing MSTest test projects |\n| Build command | No | How to build (e.g., `dotnet build`, a repo build script). Auto-detect if not provided |\n| Test command | No | How to run tests (e.g., `dotnet test`). Auto-detect if not provided |\n\n## Response Guidelines\n\n- **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.\n- **Focused fix requests** (user has specific compilation errors after upgrading): Address only the relevant breaking changes from Step 3. **Always provide concrete fixed code** using the user's actual types and method names — show a complete, copy-pasteable code snippet, not just a description of what to change. For custom `TestMethodAttribute` subclasses, show the full fixed class including CallerInfo propagation to the base constructor. Mention any related analyzer that could have caught this earlier (e.g., MSTEST0006 for ExpectedException). Do not walk through the entire migration workflow.\n- **\"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.\n- **Full migration requests** (user wants complete migration): Follow the complete workflow below.\n- **Behavioral\u002Fruntime symptom reports** (user describes test execution differences without build errors): Match described symptoms to the behavioral changes table in Step 4. Provide targeted, symptom-specific advice. Mention other behavioral changes the user should watch for. Do not walk through source breaking changes unless the user also has build errors.\n- **CI\u002Ftest-discovery issues** (tests not discovered, vstest.console stopped working, CI pipeline failures after upgrading): Focus on 4.5 (MSTest.Sdk defaults to MTP mode, which does not include Microsoft.NET.Test.Sdk -- needed for vstest.console) and 4.4 (TreatDiscoveryWarningsAsErrors). Explain the root cause clearly and give both fix options (add Microsoft.NET.Test.Sdk package or switch to `dotnet test`). Do not walk through the full migration workflow.\n- **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.\n\n## Workflow\n\n> **Commit strategy:** Commit at each logical boundary -- after updating packages (Step 2), after resolving source breaking changes (Step 3), after addressing behavioral changes (Step 4). This keeps each commit focused and reviewable.\n\n### Step 1: Assess the project\n\n1. 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`.\n2. Confirm the project is on MSTest v3 (3.x). If on v1 or v2, use `migrate-mstest-v1v2-to-v3` first.\n3. 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).\n4. Check for custom `TestMethodAttribute` subclasses -- these require changes in v4.\n5. Check for usages of `ExpectedExceptionAttribute` -- removed in v4 (deprecated since v3 with analyzer MSTEST0006).\n6. Check for usages of `Assert.ThrowsException` (deprecated) -- removed in v4.\n7. Run a clean build to establish a baseline of existing errors\u002Fwarnings.\n\n### Step 2: Update packages to MSTest v4\n\n**If using the MSTest metapackage:**\n\n```xml\n\u003CPackageReference Include=\"MSTest\" Version=\"4.1.0\" \u002F>\n```\n\n**If using individual packages:**\n\n```xml\n\u003CPackageReference Include=\"MSTest.TestFramework\" Version=\"4.1.0\" \u002F>\n\u003CPackageReference Include=\"MSTest.TestAdapter\" Version=\"4.1.0\" \u002F>\n```\n\n**If using MSTest.Sdk:**\n\n```xml\n\u003CProject Sdk=\"MSTest.Sdk\u002F4.1.0\">\n```\n\nRun `dotnet restore`, then `dotnet build`. Collect all errors for Step 3.\n\n### Step 3: Resolve source breaking changes\n\nWork through compilation errors systematically. Use this quick-lookup table to identify all applicable changes, then apply each fix:\n\n| Error \u002F Pattern in code | Breaking change | Fix |\n|---|---|---|\n| Custom `TestMethodAttribute` overrides `Execute` | Execute removed | Change to `ExecuteAsync` returning `Task\u003CTestResult[]>` (3.1) |\n| `[TestMethod(\"name\")]` or custom attribute constructor | CallerInfo params added | Use `DisplayName = \"name\"` named param; propagate CallerInfo in subclasses (3.2) |\n| `ClassCleanupBehavior.EndOfClass` | Enum removed | Remove argument: just `[ClassCleanup]` (3.3) |\n| `TestContext.Properties.Contains(\"key\")` | `Properties` is `IDictionary\u003Cstring, object>` | Change to `ContainsKey(\"key\")` (3.4) |\n| `[Timeout(TestTimeout.Infinite)]` | `TestTimeout` enum removed | Replace with `[Timeout(int.MaxValue)]` (3.5) |\n| `TestContext.ManagedType` | Property removed | Use `FullyQualifiedTestClassName` (3.6) |\n| `Assert.AreEqual(a, b, \"msg {0}\", arg)` | Message+params overloads removed | Use string interpolation: `$\"msg {arg}\"` (3.7) |\n| `Assert.ThrowsException\u003CT>(...)` | Renamed | Replace with `Assert.ThrowsExactly\u003CT>(...)` or `Assert.Throws\u003CT>(...)` (3.7) |\n| `Assert.IsInstanceOfType\u003CT>(obj, out var t)` | Out parameter removed | Use `var t = Assert.IsInstanceOfType\u003CT>(obj)` (3.7) |\n| `[ExpectedException(typeof(T))]` | Attribute removed | Move assertion into test body: `Assert.ThrowsExactly\u003CT>(() => ...)` (3.8) |\n| Project targets net5.0, net6.0, or net7.0 | TFM dropped | Change to net8.0 or net9.0 (3.9) |\n\n> **Important**: Scan the entire project for ALL patterns above before starting fixes. Multiple breaking changes often coexist in the same project.\n\n#### 3.1 TestMethodAttribute.Execute -> ExecuteAsync\n\nIf you have custom `TestMethodAttribute` subclasses that override `Execute`, change to `ExecuteAsync`. This change was made because the v3 synchronous `Execute` API caused deadlocks when test code used `async`\u002F`await` internally -- the synchronous wrapper would block the thread while the async operation needed that same thread to complete.\n\n```csharp\n\u002F\u002F Before (v3)\npublic sealed class MyTestMethodAttribute : TestMethodAttribute\n{\n    public override TestResult[] Execute(ITestMethod testMethod)\n    {\n        \u002F\u002F custom logic\n        return result;\n    }\n}\n\n\u002F\u002F After (v4) -- Option A: wrap synchronous logic with Task.FromResult\npublic sealed class MyTestMethodAttribute : TestMethodAttribute\n{\n    public override Task\u003CTestResult[]> ExecuteAsync(ITestMethod testMethod)\n    {\n        \u002F\u002F custom logic (synchronous)\n        return Task.FromResult(result);\n    }\n}\n\n\u002F\u002F After (v4) -- Option B: make properly async\npublic sealed class MyTestMethodAttribute : TestMethodAttribute\n{\n    public override async Task\u003CTestResult[]> ExecuteAsync(ITestMethod testMethod)\n    {\n        \u002F\u002F custom async logic\n        return await base.ExecuteAsync(testMethod);\n    }\n}\n```\n\nUse `Task.FromResult` when your override logic is purely synchronous. Use `async`\u002F`await` when you call `base.ExecuteAsync` or other async methods.\n\n#### 3.2 TestMethodAttribute CallerInfo constructor\n\n`TestMethodAttribute` now uses `[CallerFilePath]` and `[CallerLineNumber]` parameters in its constructor.\n\n**If you inherit from TestMethodAttribute**, propagate caller info to the base class:\n\n```csharp\npublic class MyTestMethodAttribute : TestMethodAttribute\n{\n    public MyTestMethodAttribute(\n        [CallerFilePath] string callerFilePath = \"\",\n        [CallerLineNumber] int callerLineNumber = -1)\n        : base(callerFilePath, callerLineNumber)\n    {\n    }\n}\n```\n\n**If you use `[TestMethodAttribute(\"Custom display name\")]`**, switch to the named parameter syntax:\n\n```csharp\n\u002F\u002F Before (v3)\n[TestMethodAttribute(\"Custom display name\")]\n\n\u002F\u002F After (v4)\n[TestMethodAttribute(DisplayName = \"Custom display name\")]\n```\n\n#### 3.3 ClassCleanupBehavior enum removed\n\nThe `ClassCleanupBehavior` enum is removed. In v3, this enum controlled whether class cleanup ran at end of class (`EndOfClass`) or end of assembly (`EndOfAssembly`). In v4, class cleanup always runs at end of class. Remove the enum argument:\n\n```csharp\n\u002F\u002F Before (v3)\n[ClassCleanup(ClassCleanupBehavior.EndOfClass)]\npublic static void ClassCleanup(TestContext testContext) { }\n\n\u002F\u002F After (v4)\n[ClassCleanup]\npublic static void ClassCleanup(TestContext testContext) { }\n```\n\nIf you previously used `ClassCleanupBehavior.EndOfAssembly`, move that cleanup logic to an `[AssemblyCleanup]` method instead.\n\n#### 3.4 TestContext.Properties type change\n\n`TestContext.Properties` changed from `IDictionary` to `IDictionary\u003Cstring, object>`. Update any `Contains` calls to `ContainsKey`:\n\n```csharp\n\u002F\u002F Before (v3)\ntestContext.Properties.Contains(\"key\");\n\n\u002F\u002F After (v4)\ntestContext.Properties.ContainsKey(\"key\");\n```\n\n#### 3.5 TestTimeout enum removed\n\nThe `TestTimeout` enum (with only `TestTimeout.Infinite`) is removed. Replace with `int.MaxValue`:\n\n```csharp\n\u002F\u002F Before (v3)\n[Timeout(TestTimeout.Infinite)]\n\n\u002F\u002F After (v4)\n[Timeout(int.MaxValue)]\n```\n\n#### 3.6 TestContext.ManagedType removed\n\nThe `TestContext.ManagedType` property is removed. Use `TestContext.FullyQualifiedTestClassName` instead.\n\n#### 3.7 Assert API signature changes\n\n- **Message + params removed**: Assert methods that accepted both `message` and `object[]` parameters now accept only `message`. Use string interpolation instead of format strings:\n\n```csharp\n\u002F\u002F Before (v3)\nAssert.AreEqual(expected, actual, \"Expected {0} but got {1}\", expected, actual);\n\n\u002F\u002F After (v4)\nAssert.AreEqual(expected, actual, $\"Expected {expected} but got {actual}\");\n```\n\n- **Assert.ThrowsException renamed**: The `Assert.ThrowsException` APIs are renamed. Use `Assert.ThrowsExactly` (strict type match) or `Assert.Throws` (accepts derived exception types):\n\n```csharp\n\u002F\u002F Before (v3)\nAssert.ThrowsException\u003CInvalidOperationException>(() => DoSomething());\n\n\u002F\u002F After (v4) -- exact type match (same behavior as old ThrowsException)\nAssert.ThrowsExactly\u003CInvalidOperationException>(() => DoSomething());\n\n\u002F\u002F After (v4) -- also catches derived exception types\nAssert.Throws\u003CInvalidOperationException>(() => DoSomething());\n```\n\n- **Assert.IsInstanceOfType out parameter changed**: `Assert.IsInstanceOfType\u003CT>(x, out var t)` changes to `var t = Assert.IsInstanceOfType\u003CT>(x)`:\n\n```csharp\n\u002F\u002F Before (v3)\nAssert.IsInstanceOfType\u003CMyType>(obj, out var typed);\n\n\u002F\u002F After (v4)\nvar typed = Assert.IsInstanceOfType\u003CMyType>(obj);\n```\n\n- **Assert.AreEqual for IEquatable\\\u003CT\\> removed**: If you get generic type inference errors, explicitly specify the type argument as `object`.\n\n#### 3.8 ExpectedExceptionAttribute removed\n\nThe `[ExpectedException]` attribute is removed in v4. In MSTest 3.2, the `MSTEST0006` analyzer was introduced to flag `[ExpectedException]` usage and suggest migrating to `Assert.ThrowsExactly` while still on v3 (a non-breaking change). In v4, the attribute is gone entirely. Migrate to `Assert.ThrowsExactly`:\n\n```csharp\n\u002F\u002F Before (v3)\n[ExpectedException(typeof(InvalidOperationException))]\n[TestMethod]\npublic void TestMethod()\n{\n    MyCall();\n}\n\n\u002F\u002F After (v4)\n[TestMethod]\npublic void TestMethod()\n{\n    Assert.ThrowsExactly\u003CInvalidOperationException>(() => MyCall());\n}\n```\n\n**When the test has setup code before the throwing call**, wrap only the throwing call in the lambda -- keep Arrange\u002FAct separation clear:\n\n```csharp\n\u002F\u002F Before (v3)\n[ExpectedException(typeof(ArgumentNullException))]\n[TestMethod]\npublic void Validate_NullInput_Throws()\n{\n    var service = new ValidationService();\n    service.Validate(null);  \u002F\u002F throws here\n}\n\n\u002F\u002F After (v4)\n[TestMethod]\npublic void Validate_NullInput_Throws()\n{\n    var service = new ValidationService();\n    Assert.ThrowsExactly\u003CArgumentNullException>(() => service.Validate(null));\n}\n```\n\n**For async test methods**, use `Assert.ThrowsExactlyAsync`:\n\n```csharp\n\u002F\u002F Before (v3)\n[ExpectedException(typeof(HttpRequestException))]\n[TestMethod]\npublic async Task FetchData_BadUrl_Throws()\n{\n    await client.GetAsync(\"https:\u002F\u002Flocalhost:0\");\n}\n\n\u002F\u002F After (v4)\n[TestMethod]\npublic async Task FetchData_BadUrl_Throws()\n{\n    await Assert.ThrowsExactlyAsync\u003CHttpRequestException>(\n        () => client.GetAsync(\"https:\u002F\u002Flocalhost:0\"));\n}\n```\n\n**If `[ExpectedException]` used the `AllowDerivedTypes` property**, use `Assert.ThrowsAsync\u003CT>` (base type matching) instead of `Assert.ThrowsExactlyAsync\u003CT>` (exact type matching).\n\n#### 3.9 Dropped target frameworks\n\nMSTest v4 supports: **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). All other frameworks are dropped -- including net5.0, net6.0, net7.0, and netcoreapp3.1.\n\nIf the test project targets an unsupported framework, update `TargetFramework`:\n\n```xml\n\u003C!-- Before -->\n\u003CTargetFramework>net6.0\u003C\u002FTargetFramework>\n\n\u003C!-- After -->\n\u003CTargetFramework>net8.0\u003C\u002FTargetFramework>\n```\n\n#### 3.10 Unfolding strategy moved to TestMethodAttribute\n\nThe `UnfoldingStrategy` property (introduced in MSTest 3.7) has moved from individual data source attributes (`DataRowAttribute`, `DynamicDataAttribute`) to `TestMethodAttribute`.\n\n#### 3.11 ConditionBaseAttribute.ShouldRun renamed\n\nThe `ConditionBaseAttribute.ShouldRun` property is renamed to `IsConditionMet`.\n\n#### 3.12 Internal\u002Fremoved types\n\nSeveral types previously public are now internal or removed:\n\n- `MSTestDiscoverer`, `MSTestExecutor`, `AssemblyResolver`, `LogMessageListener`\n- `TestExecutionManager`, `TestMethodInfo`, `TestResultExtensions`\n- `UnitTestOutcomeExtensions`, `GenericParameterHelper`\n- `ITestMethod` in PlatformServices assembly (the one in TestFramework is unchanged)\n\nIf your code references any of these, find alternative approaches or remove the dependency.\n\n### Step 4: Address behavioral changes\n\nThese changes won't cause build errors but may affect test runtime behavior.\n\n| Symptom | Cause | Fix |\n|---|---|---|\n| Tests show as new in Azure DevOps \u002F test history lost | `TestCase.Id` generation changed (4.3) | No code fix; history will re-baseline |\n| `TestContext.TestName` throws in `[ClassInitialize]` | v4 enforces lifecycle scope (4.2) | Move access to `[TestInitialize]` or test methods |\n| Tests not discovered \u002F discovery failures | `TreatDiscoveryWarningsAsErrors` now true (4.4) | Fix warnings, or set to false in .runsettings |\n| Tests hang that didn't before | AppDomain disabled by default (4.1) | Set `DisableAppDomain` to false in .runsettings `RunConfiguration` |\n| vstest.console can't find tests with MSTest.Sdk | MSTest.Sdk defaults to MTP; `Microsoft.NET.Test.Sdk` only added in VSTest mode (4.5) | Add explicit package reference or switch to `dotnet test` |\n| New warnings from analyzers | Analyzer severities upgraded (4.6) | Fix warnings or suppress in .editorconfig |\n\n#### 4.1 DisableAppDomain defaults to true\n\nAppDomains are disabled by default. On .NET Framework, when running inside testhost (the default for `dotnet test` and VS), MSTest re-enables AppDomains automatically. If you need to explicitly control AppDomain isolation, set it via `.runsettings`:\n\n```xml\n\u003CRunSettings>\n  \u003CRunConfiguration>\n    \u003CDisableAppDomain>false\u003C\u002FDisableAppDomain>\n  \u003C\u002FRunConfiguration>\n\u003C\u002FRunSettings>\n```\n\n#### 4.2 TestContext throws when used incorrectly\n\nMSTest v4 now throws when accessing test-specific properties in the wrong lifecycle stage:\n\n- `TestContext.FullyQualifiedTestClassName` -- cannot be accessed in `[AssemblyInitialize]`\n- `TestContext.TestName` -- cannot be accessed in `[AssemblyInitialize]` or `[ClassInitialize]`\n\n**Fix**: Move any code that accesses `TestContext.TestName` from `[ClassInitialize]` to `[TestInitialize]` or individual test methods, where per-test context is available. Do not replace `TestName` with `FullyQualifiedTestClassName` as a workaround -- they have different semantics.\n\n#### 4.3 TestCase.Id generation changed\n\nThe generation algorithm for `TestCase.Id` has changed to fix long-standing bugs. This may affect Azure DevOps test result tracking (e.g., test failure tracking over time). There is no code fix needed, but be aware of test result history discontinuity.\n\n#### 4.4 TreatDiscoveryWarningsAsErrors defaults to true\n\nv4 uses stricter defaults. Discovery warnings are now treated as errors, which means tests that previously ran despite discovery issues may now fail entirely. If you see unexpected test failures after upgrading (not build errors, but tests not being discovered), check for discovery warnings. To restore v3 behavior while you investigate:\n\n```xml\n\u003CRunSettings>\n  \u003CMSTest>\n    \u003CTreatDiscoveryWarningsAsErrors>false\u003C\u002FTreatDiscoveryWarningsAsErrors>\n  \u003C\u002FMSTest>\n\u003C\u002FRunSettings>\n```\n\n> **Recommended**: Fix the underlying discovery warnings rather than suppressing this setting.\n\n#### 4.5 MSTest.Sdk and vstest.console compatibility\n\nMSTest.Sdk defaults to Microsoft.Testing.Platform (MTP) mode. In MTP mode, MSTest.Sdk does **not** add a reference to `Microsoft.NET.Test.Sdk` -- it only adds it in VSTest mode. This is not a v4-specific change; it applies to MSTest.Sdk v3 as well. Without `Microsoft.NET.Test.Sdk`, `vstest.console` cannot discover or run tests and will silently find zero tests. This commonly surfaces during migration when a CI pipeline uses `vstest.console` but the project uses MSTest.Sdk in its default MTP mode.\n\n**Option A -- Switch to VSTest mode**: Set the `UseVSTest` property. MSTest.Sdk will then automatically add `Microsoft.NET.Test.Sdk`:\n\n```xml\n\u003CProject Sdk=\"MSTest.Sdk\u002F4.1.0\">\n  \u003CPropertyGroup>\n    \u003CTargetFramework>net8.0\u003C\u002FTargetFramework>\n    \u003CUseVSTest>true\u003C\u002FUseVSTest>\n  \u003C\u002FPropertyGroup>\n\u003C\u002FProject>\n```\n\n**Option B -- Switch CI to `dotnet test`**: Replace `vstest.console` invocations in your CI pipeline with `dotnet test`. This works natively with MTP and is the recommended long-term approach for MSTest.Sdk projects.\n\nIf you need VSTest during a transition period, Option A works without changing CI pipelines.\n\n#### 4.6 Analyzer severity changes\n\nMultiple analyzers have been upgraded from Info to Warning by default:\n\n- MSTEST0001, MSTEST0007, MSTEST0017, MSTEST0023, MSTEST0024, MSTEST0025\n- MSTEST0030, MSTEST0031, MSTEST0032, MSTEST0035, MSTEST0037, MSTEST0045\n\nReview and fix any new warnings, or suppress them in `.editorconfig` if intentional.\n\n### Step 5: Verify\n\n1. Run `dotnet build` -- confirm zero errors and review any new warnings\n2. Run `dotnet test` -- confirm all tests pass\n3. Compare test results (pass\u002Ffail counts) to the pre-migration baseline\n4. If using Azure DevOps test tracking, be aware that `TestCase.Id` changes may affect history continuity\n5. Check that no tests were silently dropped due to stricter discovery\n\n## Validation\n\n- [ ] All MSTest packages updated to 4.x\n- [ ] Project builds with zero errors\n- [ ] All tests pass with `dotnet test`\n- [ ] Custom `TestMethodAttribute` subclasses updated for `ExecuteAsync` and CallerInfo\n- [ ] `ExpectedExceptionAttribute` replaced with `Assert.ThrowsExactly`\n- [ ] `Assert.ThrowsException` replaced with `Assert.ThrowsExactly` (or `Assert.Throws`)\n- [ ] `ClassCleanupBehavior` enum usages removed\n- [ ] `TestContext.Properties.Contains` updated to `ContainsKey`\n- [ ] All target frameworks are net8.0+, net9.0, net462+, uap10.0.16299, or WinUI\n- [ ] Behavioral changes reviewed and addressed\n- [ ] No tests were lost during migration (compare test counts)\n\n## Related Skills\n\n- `writing-mstest-tests` -- for modern MSTest v4 assertion APIs and test authoring best practices\n- `run-tests` -- for running tests after migration\n\n## Common Pitfalls\n\n| Pitfall | Solution |\n|---------|----------|\n| Custom `TestMethodAttribute` still overrides `Execute` | Change to `ExecuteAsync` returning `Task\u003CTestResult[]>` |\n| `TestMethodAttribute(\"display name\")` no longer compiles | Use `TestMethodAttribute(DisplayName = \"display name\")` |\n| `ClassCleanupBehavior` enum not found | Remove the enum argument; `[ClassCleanup]` now always runs at end of class. For end-of-assembly cleanup, use `[AssemblyCleanup]` |\n| `TestContext.Properties.Contains` missing | Use `ContainsKey` -- `Properties` is now `IDictionary\u003Cstring, object>` |\n| `ExpectedException` attribute not found | Replace with `Assert.ThrowsExactly\u003CT>(() => ...)` inside the test body |\n| `Assert.ThrowsException` not found | Replace with `Assert.ThrowsExactly` (or `Assert.Throws` for derived types) |\n| `Assert.AreEqual` with format string args fails | Use string interpolation: `$\"message {value}\"` |\n| Tests hang that didn't before | AppDomain is disabled by default; on .NET Fx in testhost it is re-enabled automatically |\n| Azure DevOps test history breaks | Expected -- `TestCase.Id` generation changed; no code fix, results will re-baseline |\n| Discovery warnings now fail the run | `TreatDiscoveryWarningsAsErrors` is true by default; fix the discovery warnings |\n| Net6.0\u002Fnet7.0 targets don't compile | Update to net8.0 -- MSTest v4 supports net8.0, net9.0, net462, uap10.0.16299, modern UWP, and WinUI |\n","# MSTest v3 -> v4 Migration\n\nMigrate 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.\n\n## When to Use\n\n- Upgrading `MSTest.TestFramework`, `MSTest.TestAdapter`, or `MSTest` metapackage from 3.x to 4.x\n- Upgrading `MSTest.Sdk` from 3.x to 4.x\n- Fixing build errors after updating to MSTest v4 packages\n- Resolving behavioral changes in test execution after upgrading to MSTest v4\n- Updating custom `TestMethodAttribute` or `ConditionBaseAttribute` implementations for v4\n\n## When Not to Use\n\n- The project already uses MSTest v4 and builds cleanly -- migration is done\n- Upgrading from MSTest v1 or v2 -- use `migrate-mstest-v1v2-to-v3` first, then return here\n- The project does not use MSTest\n- Migrating between test frameworks (e.g., MSTest to xUnit or NUnit)\n\n## Inputs\n\n| Input | Required | Description |\n|-------|----------|-------------|\n| Project or solution path | Yes | The `.csproj`, `.sln`, or `.slnx` entry point containing MSTest test projects |\n| Build command | No | How to build (e.g., `dotnet build`, a repo build script). Auto-detect if not provided |\n| Test command | No | How to run tests (e.g., `dotnet test`). Auto-detect if not provided |\n\n## Response Guidelines\n\n- **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.\n- **Focused fix requests** (user has specific compilation errors after upgrading): Address only the relevant breaking changes from Step 3. **Always provide concrete fixed code** using the user's actual types and method names — show a complete, copy-pasteable code snippet, not just a description of what to change. For custom `TestMethodAttribute` subclasses, show the full fixed class including CallerInfo propagation to the base constructor. Mention any related analyzer that could have caught this earlier (e.g., MSTEST0006 for ExpectedException). Do not walk through the entire migration workflow.\n- **\"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.\n- **Full migration requests** (user wants complete migration): Follow the complete workflow below.\n- **Behavioral\u002Fruntime symptom reports** (user describes test execution differences without build errors): Match described symptoms to the behavioral changes table in Step 4. Provide targeted, symptom-specific advice. Mention other behavioral changes the user should watch for. Do not walk through source breaking changes unless the user also has build errors.\n- **CI\u002Ftest-discovery issues** (tests not discovered, vstest.console stopped working, CI pipeline failures after upgrading): Focus on 4.5 (MSTest.Sdk defaults to MTP mode, which does not include Microsoft.NET.Test.Sdk -- needed for vstest.console) and 4.4 (TreatDiscoveryWarningsAsErrors). Explain the root cause clearly and give both fix options (add Microsoft.NET.Test.Sdk package or switch to `dotnet test`). Do not walk through the full migration workflow.\n- **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.\n\n## Workflow\n\n> **Commit strategy:** Commit at each logical boundary -- after updating packages (Step 2), after resolving source breaking changes (Step 3), after addressing behavioral changes (Step 4). This keeps each commit focused and reviewable.\n\n### Step 1: Assess the project\n\n1. 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`.\n2. Confirm the project is on MSTest v3 (3.x). If on v1 or v2, use `migrate-mstest-v1v2-to-v3` first.\n3. 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).\n4. Check for custom `TestMethodAttribute` subclasses -- these require changes in v4.\n5. Check for usages of `ExpectedExceptionAttribute` -- removed in v4 (deprecated since v3 with analyzer MSTEST0006).\n6. Check for usages of `Assert.ThrowsException` (deprecated) -- removed in v4.\n7. Run a clean build to establish a baseline of existing errors\u002Fwarnings.\n\n### Step 2: Update packages to MSTest v4\n\n**If using the MSTest metapackage:**\n\n```xml\n\u003CPackageReference Include=\"MSTest\" Version=\"4.1.0\" \u002F>\n```\n\n**If using individual packages:**\n\n```xml\n\u003CPackageReference Include=\"MSTest.TestFramework\" Version=\"4.1.0\" \u002F>\n\u003CPackageReference Include=\"MSTest.TestAdapter\" Version=\"4.1.0\" \u002F>\n```\n\n**If using MSTest.Sdk:**\n\n```xml\n\u003CProject Sdk=\"MSTest.Sdk\u002F4.1.0\">\n```\n\nRun `dotnet restore`, then `dotnet build`. Collect all errors for Step 3.\n\n### Step 3: Resolve source breaking changes\n\nWork through compilation errors systematically. Use this quick-lookup table to identify all applicable changes, then apply each fix:\n\n| Error \u002F Pattern in code | Breaking change | Fix |\n|---|---|---|\n| Custom `TestMethodAttribute` overrides `Execute` | Execute removed | Change to `ExecuteAsync` returning `Task\u003CTestResult[]>` (3.1) |\n| `[TestMethod(\"name\")]` or custom attribute constructor | CallerInfo params added | Use `DisplayName = \"name\"` named param; propagate CallerInfo in subclasses (3.2) |\n| `ClassCleanupBehavior.EndOfClass` | Enum removed | Remove argument: just `[ClassCleanup]` (3.3) |\n| `TestContext.Properties.Contains(\"key\")` | `Properties` is `IDictionary\u003Cstring, object>` | Change to `ContainsKey(\"key\")` (3.4) |\n| `[Timeout(TestTimeout.Infinite)]` | `TestTimeout` enum removed | Replace with `[Timeout(int.MaxValue)]` (3.5) |\n| `TestContext.ManagedType` | Property removed | Use `FullyQualifiedTestClassName` (3.6) |\n| `Assert.AreEqual(a, b, \"msg {0}\", arg)` | Message+params overloads removed | Use string interpolation: `$\"msg {arg}\"` (3.7) |\n| `Assert.ThrowsException\u003CT>(...)` | Renamed | Replace with `Assert.ThrowsExactly\u003CT>(...)` or `Assert.Throws\u003CT>(...)` (3.7) |\n| `Assert.IsInstanceOfType\u003CT>(obj, out var t)` | Out parameter removed | Use `var t = Assert.IsInstanceOfType\u003CT>(obj)` (3.7) |\n| `[ExpectedException(typeof(T))]` | Attribute removed | Move assertion into test body: `Assert.ThrowsExactly\u003CT>(() => ...)` (3.8) |\n| Project targets net5.0, net6.0, or net7.0 | TFM dropped | Change to net8.0 or net9.0 (3.9) |\n\n> **Important**: Scan the entire project for ALL patterns above before starting fixes. Multiple breaking changes often coexist in the same project.\n\n#### 3.1 TestMethodAttribute.Execute -> ExecuteAsync\n\nIf you have custom `TestMethodAttribute` subclasses that override `Execute`, change to `ExecuteAsync`. This change was made because the v3 synchronous `Execute` API caused deadlocks when test code used `async`\u002F`await` internally -- the synchronous wrapper would block the thread while the async operation needed that same thread to complete.\n\n```csharp\n\u002F\u002F Before (v3)\npublic sealed class MyTestMethodAttribute : TestMethodAttribute\n{\n    public override TestResult[] Execute(ITestMethod testMethod)\n    {\n        \u002F\u002F custom logic\n        return result;\n    }\n}\n\n\u002F\u002F After (v4) -- Option A: wrap synchronous logic with Task.FromResult\npublic sealed class MyTestMethodAttribute : TestMethodAttribute\n{\n    public override Task\u003CTestResult[]> ExecuteAsync(ITestMethod testMethod)\n    {\n        \u002F\u002F custom logic (synchronous)\n        return Task.FromResult(result);\n    }\n}\n\n\u002F\u002F After (v4) -- Option B: make properly async\npublic sealed class MyTestMethodAttribute : TestMethodAttribute\n{\n    public override async Task\u003CTestResult[]> ExecuteAsync(ITestMethod testMethod)\n    {\n        \u002F\u002F custom async logic\n        return await base.ExecuteAsync(testMethod);\n    }\n}\n```\n\nUse `Task.FromResult` when your override logic is purely synchronous. Use `async`\u002F`await` when you call `base.ExecuteAsync` or other async methods.\n\n#### 3.2 TestMethodAttribute CallerInfo constructor\n\n`TestMethodAttribute` now uses `[CallerFilePath]` and `[CallerLineNumber]` parameters in its constructor.\n\n**If you inherit from TestMethodAttribute**, propagate caller info to the base class:\n\n```csharp\npublic class MyTestMethodAttribute : TestMethodAttribute\n{\n    public MyTestMethodAttribute(\n        [CallerFilePath] string callerFilePath = \"\",\n        [CallerLineNumber] int callerLineNumber = -1)\n        : base(callerFilePath, callerLineNumber)\n    {\n    }\n}\n```\n\n**If you use `[TestMethodAttribute(\"Custom display name\")]`**, switch to the named parameter syntax:\n\n```csharp\n\u002F\u002F Before (v3)\n[TestMethodAttribute(\"Custom display name\")]\n\n\u002F\u002F After (v4)\n[TestMethodAttribute(DisplayName = \"Custom display name\")]\n```\n\n#### 3.3 ClassCleanupBehavior enum removed\n\nThe `ClassCleanupBehavior` enum is removed. In v3, this enum controlled whether class cleanup ran at end of class (`EndOfClass`) or end of assembly (`EndOfAssembly`). In v4, class cleanup always runs at end of class. Remove the enum argument:\n\n```csharp\n\u002F\u002F Before (v3)\n[ClassCleanup(ClassCleanupBehavior.EndOfClass)]\npublic static void ClassCleanup(TestContext testContext) { }\n\n\u002F\u002F After (v4)\n[ClassCleanup]\npublic static void ClassCleanup(TestContext testContext) { }\n```\n\nIf you previously used `ClassCleanupBehavior.EndOfAssembly`, move that cleanup logic to an `[AssemblyCleanup]` method instead.\n\n#### 3.4 TestContext.Properties type change\n\n`TestContext.Properties` changed from `IDictionary` to `IDictionary\u003Cstring, object>`. Update any `Contains` calls to `ContainsKey`:\n\n```csharp\n\u002F\u002F Before (v3)\ntestContext.Properties.Contains(\"key\");\n\n\u002F\u002F After (v4)\ntestContext.Properties.ContainsKey(\"key\");\n```\n\n#### 3.5 TestTimeout enum removed\n\nThe `TestTimeout` enum (with only `TestTimeout.Infinite`) is removed. Replace with `int.MaxValue`:\n\n```csharp\n\u002F\u002F Before (v3)\n[Timeout(TestTimeout.Infinite)]\n\n\u002F\u002F After (v4)\n[Timeout(int.MaxValue)]\n```\n\n#### 3.6 TestContext.ManagedType removed\n\nThe `TestContext.ManagedType` property is removed. Use `TestContext.FullyQualifiedTestClassName` instead.\n\n#### 3.7 Assert API signature changes\n\n- **Message + params removed**: Assert methods that accepted both `message` and `object[]` parameters now accept only `message`. Use string interpolation instead of format strings:\n\n```csharp\n\u002F\u002F Before (v3)\nAssert.AreEqual(expected, actual, \"Expected {0} but got {1}\", expected, actual);\n\n\u002F\u002F After (v4)\nAssert.AreEqual(expected, actual, $\"Expected {expected} but got {actual}\");\n```\n\n- **Assert.ThrowsException renamed**: The `Assert.ThrowsException` APIs are renamed. Use `Assert.ThrowsExactly` (strict type match) or `Assert.Throws` (accepts derived exception types):\n\n```csharp\n\u002F\u002F Before (v3)\nAssert.ThrowsException\u003CInvalidOperationException>(() => DoSomething());\n\n\u002F\u002F After (v4) -- exact type match (same behavior as old ThrowsException)\nAssert.ThrowsExactly\u003CInvalidOperationException>(() => DoSomething());\n\n\u002F\u002F After (v4) -- also catches derived exception types\nAssert.Throws\u003CInvalidOperationException>(() => DoSomething());\n```\n\n- **Assert.IsInstanceOfType out parameter changed**: `Assert.IsInstanceOfType\u003CT>(x, out var t)` changes to `var t = Assert.IsInstanceOfType\u003CT>(x)`:\n\n```csharp\n\u002F\u002F Before (v3)\nAssert.IsInstanceOfType\u003CMyType>(obj, out var typed);\n\n\u002F\u002F After (v4)\nvar typed = Assert.IsInstanceOfType\u003CMyType>(obj);\n```\n\n- **Assert.AreEqual for IEquatable\\\u003CT\\> removed**: If you get generic type inference errors, explicitly specify the type argument as `object`.\n\n#### 3.8 ExpectedExceptionAttribute removed\n\nThe `[ExpectedException]` attribute is removed in v4. In MSTest 3.2, the `MSTEST0006` analyzer was introduced to flag `[ExpectedException]` usage and suggest migrating to `Assert.ThrowsExactly` while still on v3 (a non-breaking change). In v4, the attribute is gone entirely. Migrate to `Assert.ThrowsExactly`:\n\n```csharp\n\u002F\u002F Before (v3)\n[ExpectedException(typeof(InvalidOperationException))]\n[TestMethod]\npublic void TestMethod()\n{\n    MyCall();\n}\n\n\u002F\u002F After (v4)\n[TestMethod]\npublic void TestMethod()\n{\n    Assert.ThrowsExactly\u003CInvalidOperationException>(() => MyCall());\n}\n```\n\n**When the test has setup code before the throwing call**, wrap only the throwing call in the lambda -- keep Arrange\u002FAct separation clear:\n\n```csharp\n\u002F\u002F Before (v3)\n[ExpectedException(typeof(ArgumentNullException))]\n[TestMethod]\npublic void Validate_NullInput_Throws()\n{\n    var service = new ValidationService();\n    service.Validate(null);  \u002F\u002F throws here\n}\n\n\u002F\u002F After (v4)\n[TestMethod]\npublic void Validate_NullInput_Throws()\n{\n    var service = new ValidationService();\n    Assert.ThrowsExactly\u003CArgumentNullException>(() => service.Validate(null));\n}\n```\n\n**For async test methods**, use `Assert.ThrowsExactlyAsync`:\n\n```csharp\n\u002F\u002F Before (v3)\n[ExpectedException(typeof(HttpRequestException))]\n[TestMethod]\npublic async Task FetchData_BadUrl_Throws()\n{\n    await client.GetAsync(\"https:\u002F\u002Flocalhost:0\");\n}\n\n\u002F\u002F After (v4)\n[TestMethod]\npublic async Task FetchData_BadUrl_Throws()\n{\n    await Assert.ThrowsExactlyAsync\u003CHttpRequestException>(\n        () => client.GetAsync(\"https:\u002F\u002Flocalhost:0\"));\n}\n```\n\n**If `[ExpectedException]` used the `AllowDerivedTypes` property**, use `Assert.ThrowsAsync\u003CT>` (base type matching) instead of `Assert.ThrowsExactlyAsync\u003CT>` (exact type matching).\n\n#### 3.9 Dropped target frameworks\n\nMSTest v4 supports: **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). All other frameworks are dropped -- including net5.0, net6.0, net7.0, and netcoreapp3.1.\n\nIf the test project targets an unsupported framework, update `TargetFramework`:\n\n```xml\n\u003C!-- Before -->\n\u003CTargetFramework>net6.0\u003C\u002FTargetFramework>\n\n\u003C!-- After -->\n\u003CTargetFramework>net8.0\u003C\u002FTargetFramework>\n```\n\n#### 3.10 Unfolding strategy moved to TestMethodAttribute\n\nThe `UnfoldingStrategy` property (introduced in MSTest 3.7) has moved from individual data source attributes (`DataRowAttribute`, `DynamicDataAttribute`) to `TestMethodAttribute`.\n\n#### 3.11 ConditionBaseAttribute.ShouldRun renamed\n\nThe `ConditionBaseAttribute.ShouldRun` property is renamed to `IsConditionMet`.\n\n#### 3.12 Internal\u002Fremoved types\n\nSeveral types previously public are now internal or removed:\n\n- `MSTestDiscoverer`, `MSTestExecutor`, `AssemblyResolver`, `LogMessageListener`\n- `TestExecutionManager`, `TestMethodInfo`, `TestResultExtensions`\n- `UnitTestOutcomeExtensions`, `GenericParameterHelper`\n- `ITestMethod` in PlatformServices assembly (the one in TestFramework is unchanged)\n\nIf your code references any of these, find alternative approaches or remove the dependency.\n\n### Step 4: Address behavioral changes\n\nThese changes won't cause build errors but may affect test runtime behavior.\n\n| Symptom | Cause | Fix |\n|---|---|---|\n| Tests show as new in Azure DevOps \u002F test history lost | `TestCase.Id` generation changed (4.3) | No code fix; history will re-baseline |\n| `TestContext.TestName` throws in `[ClassInitialize]` | v4 enforces lifecycle scope (4.2) | Move access to `[TestInitialize]` or test methods |\n| Tests not discovered \u002F discovery failures | `TreatDiscoveryWarningsAsErrors` now true (4.4) | Fix warnings, or set to false in .runsettings |\n| Tests hang that didn't before | AppDomain disabled by default (4.1) | Set `DisableAppDomain` to false in .runsettings `RunConfiguration` |\n| vstest.console can't find tests with MSTest.Sdk | MSTest.Sdk defaults to MTP; `Microsoft.NET.Test.Sdk` only added in VSTest mode (4.5) | Add explicit package reference or switch to `dotnet test` |\n| New warnings from analyzers | Analyzer severities upgraded (4.6) | Fix warnings or suppress in .editorconfig |\n\n#### 4.1 DisableAppDomain defaults to true\n\nAppDomains are disabled by default. On .NET Framework, when running inside testhost (the default for `dotnet test` and VS), MSTest re-enables AppDomains automatically. If you need to explicitly control AppDomain isolation, set it via `.runsettings`:\n\n```xml\n\u003CRunSettings>\n  \u003CRunConfiguration>\n    \u003CDisableAppDomain>false\u003C\u002FDisableAppDomain>\n  \u003C\u002FRunConfiguration>\n\u003C\u002FRunSettings>\n```\n\n#### 4.2 TestContext throws when used incorrectly\n\nMSTest v4 now throws when accessing test-specific properties in the wrong lifecycle stage:\n\n- `TestContext.FullyQualifiedTestClassName` -- cannot be accessed in `[AssemblyInitialize]`\n- `TestContext.TestName` -- cannot be accessed in `[AssemblyInitialize]` or `[ClassInitialize]`\n\n**Fix**: Move any code that accesses `TestContext.TestName` from `[ClassInitialize]` to `[TestInitialize]` or individual test methods, where per-test context is available. Do not replace `TestName` with `FullyQualifiedTestClassName` as a workaround -- they have different semantics.\n\n#### 4.3 TestCase.Id generation changed\n\nThe generation algorithm for `TestCase.Id` has changed to fix long-standing bugs. This may affect Azure DevOps test result tracking (e.g., test failure tracking over time). There is no code fix needed, but be aware of test result history discontinuity.\n\n#### 4.4 TreatDiscoveryWarningsAsErrors defaults to true\n\nv4 uses stricter defaults. Discovery warnings are now treated as errors, which means tests that previously ran despite discovery issues may now fail entirely. If you see unexpected test failures after upgrading (not build errors, but tests not being discovered), check for discovery warnings. To restore v3 behavior while you investigate:\n\n```xml\n\u003CRunSettings>\n  \u003CMSTest>\n    \u003CTreatDiscoveryWarningsAsErrors>false\u003C\u002FTreatDiscoveryWarningsAsErrors>\n  \u003C\u002FMSTest>\n\u003C\u002FRunSettings>\n```\n\n> **Recommended**: Fix the underlying discovery warnings rather than suppressing this setting.\n\n#### 4.5 MSTest.Sdk and vstest.console compatibility\n\nMSTest.Sdk defaults to Microsoft.Testing.Platform (MTP) mode. In MTP mode, MSTest.Sdk does **not** add a reference to `Microsoft.NET.Test.Sdk` -- it only adds it in VSTest mode. This is not a v4-specific change; it applies to MSTest.Sdk v3 as well. Without `Microsoft.NET.Test.Sdk`, `vstest.console` cannot discover or run tests and will silently find zero tests. This commonly surfaces during migration when a CI pipeline uses `vstest.console` but the project uses MSTest.Sdk in its default MTP mode.\n\n**Option A -- Switch to VSTest mode**: Set the `UseVSTest` property. MSTest.Sdk will then automatically add `Microsoft.NET.Test.Sdk`:\n\n```xml\n\u003CProject Sdk=\"MSTest.Sdk\u002F4.1.0\">\n  \u003CPropertyGroup>\n    \u003CTargetFramework>net8.0\u003C\u002FTargetFramework>\n    \u003CUseVSTest>true\u003C\u002FUseVSTest>\n  \u003C\u002FPropertyGroup>\n\u003C\u002FProject>\n```\n\n**Option B -- Switch CI to `dotnet test`**: Replace `vstest.console` invocations in your CI pipeline with `dotnet test`. This works natively with MTP and is the recommended long-term approach for MSTest.Sdk projects.\n\nIf you need VSTest during a transition period, Option A works without changing CI pipelines.\n\n#### 4.6 Analyzer severity changes\n\nMultiple analyzers have been upgraded from Info to Warning by default:\n\n- MSTEST0001, MSTEST0007, MSTEST0017, MSTEST0023, MSTEST0024, MSTEST0025\n- MSTEST0030, MSTEST0031, MSTEST0032, MSTEST0035, MSTEST0037, MSTEST0045\n\nReview and fix any new warnings, or suppress them in `.editorconfig` if intentional.\n\n### Step 5: Verify\n\n1. Run `dotnet build` -- confirm zero errors and review any new warnings\n2. Run `dotnet test` -- confirm all tests pass\n3. Compare test results (pass\u002Ffail counts) to the pre-migration baseline\n4. If using Azure DevOps test tracking, be aware that `TestCase.Id` changes may affect history continuity\n5. Check that no tests were silently dropped due to stricter discovery\n\n## Validation\n\n- [ ] All MSTest packages updated to 4.x\n- [ ] Project builds with zero errors\n- [ ] All tests pass with `dotnet test`\n- [ ] Custom `TestMethodAttribute` subclasses updated for `ExecuteAsync` and CallerInfo\n- [ ] `ExpectedExceptionAttribute` replaced with `Assert.ThrowsExactly`\n- [ ] `Assert.ThrowsException` replaced with `Assert.ThrowsExactly` (or `Assert.Throws`)\n- [ ] `ClassCleanupBehavior` enum usages removed\n- [ ] `TestContext.Properties.Contains` updated to `ContainsKey`\n- [ ] All target frameworks are net8.0+, net9.0, net462+, uap10.0.16299, or WinUI\n- [ ] Behavioral changes reviewed and addressed\n- [ ] No tests were lost during migration (compare test counts)\n\n## Related Skills\n\n- `writing-mstest-tests` -- for modern MSTest v4 assertion APIs and test authoring best practices\n- `run-tests` -- for running tests after migration\n\n## Common Pitfalls\n\n| Pitfall | Solution |\n|---------|----------|\n| Custom `TestMethodAttribute` still overrides `Execute` | Change to `ExecuteAsync` returning `Task\u003CTestResult[]>` |\n| `TestMethodAttribute(\"display name\")` no longer compiles | Use `TestMethodAttribute(DisplayName = \"display name\")` |\n| `ClassCleanupBehavior` enum not found | Remove the enum argument; `[ClassCleanup]` now always runs at end of class. For end-of-assembly cleanup, use `[AssemblyCleanup]` |\n| `TestContext.Properties.Contains` missing | Use `ContainsKey` -- `Properties` is now `IDictionary\u003Cstring, object>` |\n| `ExpectedException` attribute not found | Replace with `Assert.ThrowsExactly\u003CT>(() => ...)` inside the test body |\n| `Assert.ThrowsException` not found | Replace with `Assert.ThrowsExactly` (or `Assert.Throws` for derived types) |\n| `Assert.AreEqual` with format string args fails | Use string interpolation: `$\"message {value}\"` |\n| Tests hang that didn't before | AppDomain is disabled by default; on .NET Fx in testhost it is re-enabled automatically |\n| Azure DevOps test history breaks | Expected -- `TestCase.Id` generation changed; no code fix, results will re-baseline |\n| Discovery warnings now fail the run | `TreatDiscoveryWarningsAsErrors` is true by default; fix the discovery warnings |\n| Net6.0\u002Fnet7.0 targets don't compile | Update to net8.0 -- MSTest v4 supports net8.0, net9.0, net462, uap10.0.16299, modern UWP, and WinUI |\n",{"name":5,"license":15,"description":24},"Fix build errors and breaking changes after upgrading MSTest from v3 to v4, or plan a complete MSTest v3-to-v4 migration. Use when user says \"upgrade to MSTest v4\", \"MSTest 4 migration\", \"MSTest v4 breaking changes\", \"tests don't compile after upgrading MSTest\", or has errors CS0507, CS0103, CS1061, CS1615 after updating MSTest packages from 3.x to 4.x. USE FOR: Execute to ExecuteAsync, CallerInfo constructor on TestMethodAttribute, sealed custom attributes, ClassCleanupBehavior removal, TestContext.Properties Contains to ContainsKey, Assert.ThrowsException to ThrowsExactly, Assert.IsInstanceOfType out parameter removal, ExpectedExceptionAttribute removal, TestTimeout enum removal, [TestMethod(\"name\")] to DisplayName syntax, TreatDiscoveryWarningsAsErrors, TestContext.TestName in ClassInitialize, MSTest.Sdk MTP changes, dropped TFMs (net6.0\u002Fnet7.0 to net8.0+). DO NOT USE FOR: migrating from MSTest v1\u002Fv2 to v3 (use migrate-mstest-v1v2-to-v3 first), migrating between test frameworks, or general .NET upgrades.\n","main","5810d492c9b301d8227f932bf87b5c954c4fa4d6","plugins\u002Fdotnet-test\u002Fskills\u002Fmigrate-mstest-v3-to-v4","https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd\u002Fskills","https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd","weiflycc.com","2026-11-10 03:26:55",{"source":8,"skillName":5,"commands":33,"prompt":43,"zipAvailable":44},[34,37,40],{"tool":35,"command":36},"npx","npx skills add weiflycc-cmd\u002Fskills --skill migrate-mstest-v3-to-v4",{"tool":38,"command":39},"bunx","bunx skills add weiflycc-cmd\u002Fskills --skill migrate-mstest-v3-to-v4",{"tool":41,"command":42},"pnpm","pnpm dlx skills add weiflycc-cmd\u002Fskills --skill migrate-mstest-v3-to-v4","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd\u002Fskills\u002Fblob\u002Fmain\u002Fplugins\u002Fdotnet-test\u002Fskills\u002Fmigrate-mstest-v3-to-v4\u002FSKILL.md",true,[],[47,54,61,68,75,82],{"skillNo":48,"name":49,"nameZh":6,"description":50,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":51,"categories":52,"keywords":53,"publishedAt":19},"01M76SGT4WG5682JQJ0V3NSK6X","system-text-json-net11","Provides guidance on new System.Text.Json APIs introduced in .NET 11. It covers typed JsonTypeInfo access via GetTypeInfo\u003CT> and TryGetTypeInfo\u003CT> on JsonSerializerOptions, and the new JsonNamingPolicy.PascalCase static property. Use when serializing or deserializing JSON in .NET 11 applications and needing typed metadata access or PascalCase property naming.","https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd\u002Fskills\u002Fblob\u002Fmain\u002Fplugins\u002Fdotnet11\u002Fskills\u002Fsystem-text-json-net11\u002FSKILL.md",[],[],{"skillNo":55,"name":56,"nameZh":6,"description":57,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":58,"categories":59,"keywords":60,"publishedAt":19},"01M76SGPNZYYV9BCZJW7BF7J8A","nuget-trusted-publishing","Set up NuGet trusted publishing (OIDC) on a GitHub Actions repo — replaces long-lived API keys with short-lived tokens. USE FOR: trusted publishing, NuGet OIDC, keyless NuGet publish, migrate from NuGet API key, NuGet\u002Flogin, secure NuGet publishing. DO NOT USE FOR: publishing to private feeds or Azure Artifacts (OIDC is nuget.org only). INVOKES: shell (powershell or bash), edit, create, ask_user for guided repo setup.","https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd\u002Fskills\u002Fblob\u002Fmain\u002Fplugins\u002Fdotnet\u002Fskills\u002Fnuget-trusted-publishing\u002FSKILL.md",[],[],{"skillNo":62,"name":63,"nameZh":6,"description":64,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":65,"categories":66,"keywords":67,"publishedAt":19},"01M76SGHVNBNVM1DMVDYTMAE5G","dotnet-pinvoke","Correctly call native (C\u002FC++) libraries from .NET using P\u002FInvoke and LibraryImport. Covers function signatures, string marshalling, memory lifetime, SafeHandle, and cross-platform patterns. USE FOR: writing new P\u002FInvoke or LibraryImport declarations, reviewing or debugging existing native interop code, wrapping a C or C++ library for use in .NET, diagnosing crashes, memory leaks, or corruption at the managed\u002Fnative boundary. DO NOT USE FOR: COM interop, C++\u002FCLI mixed-mode assemblies, or pure managed code with no native dependencies.","https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd\u002Fskills\u002Fblob\u002Fmain\u002Fplugins\u002Fdotnet\u002Fskills\u002Fdotnet-pinvoke\u002FSKILL.md",[],[],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":19},"01M76SGDB9Z3GSB1CFW314NC84","csharp-scripts","Run file-based C# apps with the .NET CLI when the user explicitly wants C#\u002F.NET code without creating a project. Use for C# language\u002FAPI experiments, one-file C# apps, small multi-file C# apps composed with `#:include`\u002F`#:exclude`, or C# file-based apps linked with `#:ref`. Do not use for language-agnostic throwaway scripts, generic computations, Python\u002FPowerShell-style automation, full projects, or existing app integration.","https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd\u002Fskills\u002Fblob\u002Fmain\u002Fplugins\u002Fdotnet\u002Fskills\u002Fcsharp-scripts\u002FSKILL.md",[],[],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":19},"01M76SG805T8W764WAKB1NP3CJ","thread-abort-migration","Guides migration of .NET Framework Thread.Abort usage to cooperative cancellation in modern .NET. USE FOR: modernizing code that calls Thread.Abort, catching ThreadAbortException, replacing Thread.ResetAbort, replacing Thread.Interrupt for thread termination, resolving PlatformNotSupportedException or SYSLIB0006 after retargeting to .NET 6+, migrating ASP.NET Response.End or Response.Redirect(url, true) which internally call Thread.Abort. DO NOT USE FOR: code that only uses Thread.Join, Thread.Sleep, or Thread.Start without any abort, interrupt, or ThreadAbortException usage — these APIs work identically in modern .NET and need no migration. Also not for projects staying on .NET Framework, or Thread.Abort usage inside third-party libraries you do not control.","https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd\u002Fskills\u002Fblob\u002Fmain\u002Fplugins\u002Fdotnet-upgrade\u002Fskills\u002Fthread-abort-migration\u002FSKILL.md",[],[],{"skillNo":83,"name":84,"nameZh":6,"description":85,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":19},"01M76SG2588ZJBE5C51HYJJSKV","migrate-nullable-references","Enable nullable reference types in a C# project and systematically resolve all warnings. USE FOR: adopting NRTs in existing codebases, file-by-file or project-wide migration, fixing CS8602\u002FCS8618\u002FCS86xx warnings, annotating APIs for nullability, cleaning up null-forgiving operators, upgrading dependencies with new nullable annotations. DO NOT USE FOR: projects already fully migrated with zero warnings (unless auditing suppressions), fixing a handful of nullable warnings in code that already has NRTs enabled, suppressing warnings without fixing them, C# 7.3 or earlier projects. INVOKES: Get-NullableReadiness.ps1 scanner script.","https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd\u002Fskills\u002Fblob\u002Fmain\u002Fplugins\u002Fdotnet-upgrade\u002Fskills\u002Fmigrate-nullable-references\u002FSKILL.md",[],[]]