platform-detection

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Test Platform and Framework Detection

测试平台与框架检测

Determine which test platform (VSTest or Microsoft.Testing.Platform) and which test framework (MSTest, xUnit, NUnit, TUnit) a project uses.
Detection files to always check (in order):
global.json
.csproj
Directory.Build.props
Directory.Packages.props
确定项目使用的测试平台(VSTest 或 Microsoft.Testing.Platform)和测试框架(MSTest、xUnit、NUnit、TUnit)。
需始终检查的检测文件(按顺序)
global.json
.csproj
Directory.Build.props
Directory.Packages.props

Detecting the test framework

检测测试框架

Read the
.csproj
file and
Directory.Build.props
/
Directory.Packages.props
(for centrally managed dependencies) and look for:
Package or SDK referenceFramework
MSTest
(metapackage, recommended) or
<Sdk Name="MSTest.Sdk">
MSTest
MSTest.TestFramework
+
MSTest.TestAdapter
MSTest (also valid for v3/v4)
xunit
,
xunit.v3
,
xunit.v3.mtp-v1
,
xunit.v3.mtp-v2
,
xunit.v3.core.mtp-v1
,
xunit.v3.core.mtp-v2
xUnit
NUnit
+
NUnit3TestAdapter
NUnit
TUnit
TUnit (MTP only)
读取
.csproj
文件以及
Directory.Build.props
/
Directory.Packages.props
(用于集中管理依赖),查找以下内容:
包或SDK引用框架
MSTest
(元包,推荐)或
<Sdk Name="MSTest.Sdk">
MSTest
MSTest.TestFramework
+
MSTest.TestAdapter
MSTest(v3/v4版本同样适用)
xunit
,
xunit.v3
,
xunit.v3.mtp-v1
,
xunit.v3.mtp-v2
,
xunit.v3.core.mtp-v1
,
xunit.v3.core.mtp-v2
xUnit
NUnit
+
NUnit3TestAdapter
NUnit
TUnit
TUnit(仅支持MTP)

Detecting the test platform

检测测试平台

The detection logic depends on the .NET SDK version. Run
dotnet --version
to determine it.
检测逻辑取决于 .NET SDK 版本。运行
dotnet --version
进行确认。

.NET SDK 10+

.NET SDK 10+

On .NET 10+, the
global.json
test.runner
setting is the authoritative source:
  • If
    global.json
    contains
    "test": { "runner": "Microsoft.Testing.Platform" }
    MTP
  • If
    global.json
    has
    "runner": "VSTest"
    , or no
    test
    section exists → VSTest
Important: On .NET 10+,
<TestingPlatformDotnetTestSupport>
alone does not switch to MTP. The
global.json
runner setting takes precedence. If the runner is VSTest (or unset), the project uses VSTest regardless of
TestingPlatformDotnetTestSupport
.
在 .NET 10+ 版本中,
global.json
中的
test.runner
配置是权威依据
  • 如果
    global.json
    包含
    "test": { "runner": "Microsoft.Testing.Platform" }
    MTP
  • 如果
    global.json
    配置为
    "runner": "VSTest"
    ,或不存在
    test
    配置段 → VSTest
重要提示:在 .NET 10+ 版本中,仅靠
<TestingPlatformDotnetTestSupport>
配置不会切换到 MTP。
global.json
中的运行器配置优先级最高。如果运行器配置为 VSTest(或未设置),无论
TestingPlatformDotnetTestSupport
配置如何,项目都会使用 VSTest。

.NET SDK 8 or 9

.NET SDK 8 或 9

On older SDKs, check these signals in priority order:
1. Check the
<TestingPlatformDotnetTestSupport>
MSBuild property.
Look in the
.csproj
,
Directory.Build.props
, and
Directory.Packages.props
. If set to
true
in any of these files, the project uses MTP.
Critical: Always read
Directory.Build.props
and
Directory.Packages.props
if they exist. MTP properties are frequently set there instead of in the
.csproj
, so checking only the project file will miss them.
2. Check project-level signals:
SignalPlatform
<Sdk Name="MSTest.Sdk">
as project SDK
MTP by default
<UseMicrosoftTestingPlatformRunner>true</UseMicrosoftTestingPlatformRunner>
MTP runner (xUnit)
<EnableMSTestRunner>true</EnableMSTestRunner>
MTP runner (MSTest)
<EnableNUnitRunner>true</EnableNUnitRunner>
MTP runner (NUnit)
Microsoft.Testing.Platform
package referenced directly
MTP
TUnit
package referenced
MTP (TUnit is MTP-only)
Note: The presence of
Microsoft.NET.Test.Sdk
does not necessarily mean VSTest. Some frameworks (e.g., MSTest) pull it in transitively for compatibility, even when MTP is enabled. Do not use this package as a signal on its own — always check the MTP signals above first.
Key distinction: VSTest is the classic platform that uses
vstest.console
under the hood. Microsoft.Testing.Platform (MTP) is the newer, faster platform. Both can be invoked via
dotnet test
, but their filter syntax and CLI options differ.
在旧版本SDK中,按优先级顺序检查以下信号:
1. 检查
<TestingPlatformDotnetTestSupport>
MSBuild 属性。
查看
.csproj
Directory.Build.props
以及
Directory.Packages.props
文件。如果任意文件中该属性设为
true
,则项目使用 MTP
关键提示:如果存在
Directory.Build.props
Directory.Packages.props
请务必读取。MTP 属性经常被设置在这两个文件而非
.csproj
中,因此仅检查项目文件会漏掉相关配置。
2. 检查项目级信号:
信号平台
项目SDK为
<Sdk Name="MSTest.Sdk">
默认使用 MTP
<UseMicrosoftTestingPlatformRunner>true</UseMicrosoftTestingPlatformRunner>
MTP 运行器(xUnit)
<EnableMSTestRunner>true</EnableMSTestRunner>
MTP 运行器(MSTest)
<EnableNUnitRunner>true</EnableNUnitRunner>
MTP 运行器(NUnit)
直接引用
Microsoft.Testing.Platform
MTP
引用
TUnit
MTP(TUnit仅支持MTP)
注意:存在
Microsoft.NET.Test.Sdk
并不一定代表使用 VSTest。部分框架(如 MSTest)为了兼容性会传递引入该包,哪怕已启用 MTP。请勿单独将该包作为判断依据 —— 始终优先检查上述MTP相关信号。
核心区别:VSTest 是底层使用
vstest.console
的传统平台。Microsoft.Testing.Platform (MTP) 是更新、更快的平台。两者都可以通过
dotnet test
调用,但它们的过滤语法和CLI选项有所不同。