platform-detection
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTest 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.csprojDirectory.Build.propsDirectory.Packages.props确定项目使用的测试平台(VSTest 或 Microsoft.Testing.Platform)和测试框架(MSTest、xUnit、NUnit、TUnit)。
需始终检查的检测文件(按顺序): → → →
global.json.csprojDirectory.Build.propsDirectory.Packages.propsDetecting the test framework
检测测试框架
Read the file and / (for centrally managed dependencies) and look for:
.csprojDirectory.Build.propsDirectory.Packages.props| Package or SDK reference | Framework |
|---|---|
| MSTest |
| MSTest (also valid for v3/v4) |
| xUnit |
| NUnit |
| TUnit (MTP only) |
读取 文件以及 / (用于集中管理依赖),查找以下内容:
.csprojDirectory.Build.propsDirectory.Packages.props| 包或SDK引用 | 框架 |
|---|---|
| MSTest |
| MSTest(v3/v4版本同样适用) |
| xUnit |
| NUnit |
| TUnit(仅支持MTP) |
Detecting the test platform
检测测试平台
The detection logic depends on the .NET SDK version. Run to determine it.
dotnet --version检测逻辑取决于 .NET SDK 版本。运行 进行确认。
dotnet --version.NET SDK 10+
.NET SDK 10+
On .NET 10+, the setting is the authoritative source:
global.jsontest.runner- If contains
global.json→ MTP"test": { "runner": "Microsoft.Testing.Platform" } - If has
global.json, or no"runner": "VSTest"section exists → VSTesttest
Important: On .NET 10+,alone does not switch to MTP. The<TestingPlatformDotnetTestSupport>runner setting takes precedence. If the runner is VSTest (or unset), the project uses VSTest regardless ofglobal.json.TestingPlatformDotnetTestSupport
在 .NET 10+ 版本中, 中的 配置是权威依据:
global.jsontest.runner- 如果 包含
global.json→ MTP"test": { "runner": "Microsoft.Testing.Platform" } - 如果 配置为
global.json,或不存在"runner": "VSTest"配置段 → VSTesttest
重要提示:在 .NET 10+ 版本中,仅靠配置不会切换到 MTP。<TestingPlatformDotnetTestSupport>中的运行器配置优先级最高。如果运行器配置为 VSTest(或未设置),无论global.json配置如何,项目都会使用 VSTest。TestingPlatformDotnetTestSupport
.NET SDK 8 or 9
.NET SDK 8 或 9
On older SDKs, check these signals in priority order:
1. Check the MSBuild property. Look in the , , and . If set to in any of these files, the project uses MTP.
<TestingPlatformDotnetTestSupport>.csprojDirectory.Build.propsDirectory.Packages.propstrueCritical: Always readandDirectory.Build.propsif they exist. MTP properties are frequently set there instead of in theDirectory.Packages.props, so checking only the project file will miss them..csproj
2. Check project-level signals:
| Signal | Platform |
|---|---|
| MTP by default |
| MTP runner (xUnit) |
| MTP runner (MSTest) |
| MTP runner (NUnit) |
| MTP |
| MTP (TUnit is MTP-only) |
Note: The presence ofdoes 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.Microsoft.NET.Test.Sdk
Key distinction: VSTest is the classic platform that usesunder the hood. Microsoft.Testing.Platform (MTP) is the newer, faster platform. Both can be invoked viavstest.console, but their filter syntax and CLI options differ.dotnet test
在旧版本SDK中,按优先级顺序检查以下信号:
1. 检查 MSBuild 属性。 查看 、 以及 文件。如果任意文件中该属性设为 ,则项目使用 MTP。
<TestingPlatformDotnetTestSupport>.csprojDirectory.Build.propsDirectory.Packages.propstrue关键提示:如果存在和Directory.Build.props请务必读取。MTP 属性经常被设置在这两个文件而非Directory.Packages.props中,因此仅检查项目文件会漏掉相关配置。.csproj
2. 检查项目级信号:
| 信号 | 平台 |
|---|---|
项目SDK为 | 默认使用 MTP |
| MTP 运行器(xUnit) |
| MTP 运行器(MSTest) |
| MTP 运行器(NUnit) |
直接引用 | MTP |
引用 | MTP(TUnit仅支持MTP) |
注意:存在并不一定代表使用 VSTest。部分框架(如 MSTest)为了兼容性会传递引入该包,哪怕已启用 MTP。请勿单独将该包作为判断依据 —— 始终优先检查上述MTP相关信号。Microsoft.NET.Test.Sdk
核心区别:VSTest 是底层使用的传统平台。Microsoft.Testing.Platform (MTP) 是更新、更快的平台。两者都可以通过vstest.console调用,但它们的过滤语法和CLI选项有所不同。dotnet test