skip to content

In MSTest 4, what does a test project built on MSTest.Sdk set up for you that a Microsoft.NET.Sdk project with MSTest packages does not?

level: juniorimportance: should knowfreq 38%

answer

  1. one Sdk attribute instead of package lines
  2. OutputType Exe, IsPackable false
  3. UseVSTest defaults to false
  4. extensions chosen by a profile
  5. IsTestApplication false for helpers

basics

~20 s

MSTest.Sdk is a project SDK layered on Microsoft.NET.Sdk: it references the MSTest framework and adapter at one version, makes the project a Microsoft.Testing.Platform executable (UseVSTest defaults to false) and adds TRX and coverage extensions through a profile.

solid answer

~40 s

With `<Project Sdk="MSTest.Sdk/4.4.1">` the project file shrinks to a target framework. The SDK imports `Microsoft.NET.Sdk` itself, references `MSTest.TestFramework` and `MSTest.TestAdapter` at the SDK's own version, sets `OutputType` to `Exe` and `IsPackable` to `false`, and turns on the MSTest runner so the project is a **Microsoft.Testing.Platform** test application. `UseVSTest` defaults to `false` (only UWP flips it); setting it to `true` switches to VSTest, and only then does MSTest 4's SDK add `Microsoft.NET.Test.Sdk`. `TestingExtensionsProfile` (default `Default`) decides which `Microsoft.Testing.Extensions.*` packages come along — TRX reporting and code coverage by default — and `Enable…` properties add or drop single ones. A shared helper project sets `IsTestApplication` to `false`. The classic alternative, `Microsoft.NET.Sdk` plus the `MSTest` metapackage, still brings `Microsoft.NET.Test.Sdk` and VSTest.

code

xml · 13 lines
xml
<Project Sdk="MSTest.Sdk/4.4.1">

  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <!-- Optional: AllMicrosoft adds dumps, retry and HTML report -->
    <TestingExtensionsProfile>Default</TestingExtensionsProfile>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\..\src\Billing\Billing.csproj" />
  </ItemGroup>

</Project>

go deeper

for a junior

Recall the one-line project: Sdk="MSTest.Sdk/4.4.1" with a target framework, and that it brings the MSTest packages and makes the project an executable test app.

for a middle

Explain the defaults it applies — OutputType Exe, UseVSTest false, the Default extensions profile — and when IsTestApplication false or UseVSTest true is needed.

for a senior

Weigh MSTest.Sdk against package references for a solution: one version moves everything, but CI and tooling must be ready for Microsoft.Testing.Platform or pinned to VSTest.

for a principal

Decide a repository-wide test project convention: SDK pinning in global.json, shared props for profile and runner, and who owns upgrades of the test toolchain.

## Two ways to build an MSTest project An MSTest 4 test project can be built in two styles: 1. **Package style** — `<Project Sdk="Microsoft.NET.Sdk">` plus package references, usually the `MSTest` metapackage. That metapackage brings `MSTest.TestFramework`, `MSTest.TestAdapter`, `Microsoft.Testing.Extensions.TrxReport`, `Microsoft.Testing.Extensions.CodeCoverage` and `Microsoft.NET.Test.Sdk`, the package that wires a project into **VSTest**. 2. **SDK style** — `<Project Sdk="MSTest.Sdk/4.4.1">`. **MSTest.Sdk** is an MSBuild project SDK shipped from the MSTest repository. It layers on top of `Microsoft.NET.Sdk` (importing it unless another SDK such as `Microsoft.NET.Sdk.Web` already did) and makes the remaining decisions through MSBuild properties. The SDK's version is the version of everything it references, so it is pinned either in the `Sdk` attribute or once for the repository in `global.json` under `msbuild-sdks`. ## What MSTest.Sdk sets for a test application | Setting | Value MSTest.Sdk applies | |---|---| | `OutputType` | `Exe` — the test project is an executable | | `IsPackable` | `false` | | `UseVSTest` | `false`, unless the project is a UWP app | | `EnableMSTestRunner` / `IsTestingPlatformApplication` | `true` — runs on Microsoft.Testing.Platform | | `TestingExtensionsProfile` | `Default` | | Package references | `MSTest.TestFramework`, `MSTest.TestAdapter`, plus the profile's extensions | | Implicit using | `Microsoft.VisualStudio.TestTools.UnitTesting` when `ImplicitUsings` is on | The result is a project file that says only what is specific to it — usually just the target framework and project references to the code under test. ## The runner switch: `UseVSTest` By default an MSTest.Sdk project runs on **Microsoft.Testing.Platform (MTP)**: the build generates an entry point, and the test project runs as its own process, directly or through tooling. Setting `<UseVSTest>true</UseVSTest>` imports the SDK's VSTest branch instead, which references `Microsoft.NET.Test.Sdk` so that `vstest.console` and IDEs relying on VSTest can run it. A detail changed in MSTest 4: the 3.x SDK added `Microsoft.NET.Test.Sdk` even on the MTP path. MSTest 4 removed it, so a pipeline that still calls `vstest.console` directly on an MTP project stops working until it moves to MTP, sets `UseVSTest` back to `true`, or references `Microsoft.NET.Test.Sdk` explicitly, as the migration guide describes for keeping `vstest.console` support. ## Extensions by profile MTP features such as TRX reports, coverage, crash and hang dumps, and retries ship as separate `Microsoft.Testing.Extensions.*` packages. MSTest.Sdk picks them with **`TestingExtensionsProfile`**: - `Default` — TRX report and Microsoft code coverage; - `AllMicrosoft` — those plus crash dump, hang dump, hot reload, retry, HTML report, Fakes, and the Azure DevOps and GitHub Actions reporters; - `None` — no extensions. Any single extension can be forced on or off with a property named after its package without dots, for example `<EnableMicrosoftTestingExtensionsCodeCoverage>false</EnableMicrosoftTestingExtensionsCodeCoverage>`. Referencing an extension only makes its command-line options available; a TRX file, for instance, is written when the run asks for it. ## Helper libraries and features - A project with shared test utilities but no tests of its own sets **`<IsTestApplication>false</IsTestApplication>`**: it keeps `MSTest.TestFramework` for the attributes and `Assert`, but gets no adapter, no extensions and no entry point. Projects targeting .NET Standard default to `false` for the same reason. - **`EnableAspireTesting`** and **`EnablePlaywright`** (both `false` by default) add the packages and usings for Aspire integration tests and Playwright browser tests. ## Mistakes seen during conversion - **Keeping the old package lines.** Leaving a `PackageReference` to `MSTest`, `MSTest.TestFramework` or `Microsoft.NET.Test.Sdk` next to the SDK duplicates what it already adds, and the last one brings VSTest wiring back. - **Forcing `OutputType` to `Library`.** A test application on Microsoft.Testing.Platform must be an executable; a library-typed project has no entry point to run. - **Forgetting the version.** Without a version in the `Sdk` attribute or in `global.json`, MSBuild cannot resolve the SDK; pinning it in `global.json` keeps every project on the same release. - **Converting one project at a time in CI.** A solution that is half MTP and half VSTest is unsupported by `dotnet test`; convert all test projects together or keep the stragglers on `UseVSTest`. ## When to keep the package style MSTest.Sdk is a convenience, not a requirement: everything it does can be written by hand with package references and properties. Teams keep the package style when a central build already manages every package version, or when tooling expects plain `Microsoft.NET.Sdk` projects. The trade-off is more lines to keep in sync; the SDK's main value is that one version number moves the framework, adapter, platform and extensions together.

  • What happens if a shared test-utilities project uses MSTest.Sdk without IsTestApplication set to false?
    It is treated as a test application: it becomes an executable, gets the adapter, an entry point and the profile's extensions, and tooling tries to run it — where MTP fails a run that finds no tests by default. Setting `IsTestApplication` to `false` keeps only `MSTest.TestFramework` so the project compiles as an ordinary library.
  • How do you keep an MSTest.Sdk project on VSTest while the CI is not ready for Microsoft.Testing.Platform?
    Set `<UseVSTest>true</UseVSTest>`. MSTest.Sdk then imports its VSTest branch, which references `Microsoft.NET.Test.Sdk` and the MSTest adapter, so `vstest.console` and VSTest-mode runs work as before. Remove any `TestingExtensionsProfile` or `Enable…` extension property, which that branch rejects with a build error, and set the switch for every test project, typically in a shared props file.

  • MSTest.Sdk projects run on VSTest unless you opt into Microsoft.Testing.Platform.
  • An MSTest.Sdk project still needs a Microsoft.NET.Test.Sdk PackageReference to run.
  • TestingExtensionsProfile Default writes a TRX file on every run.
  • A helper library on MSTest.Sdk needs IsPackable false to stop it being run.
  • MSTest.Sdk replaces Microsoft.NET.Sdk, so web SDK features are lost.

Assumes MSTest.Sdk 4.4.1: UseVSTest defaults to false, and since MSTest 4 the SDK adds Microsoft.NET.Test.Sdk only when UseVSTest is true.