|
2 | 2 |
|
3 | 3 | The `Microsoft.Build.RunVSTest` MSBuild SDK adds support for running tests from MSBuild, similarly to how one would use `dotnet test`.
|
4 | 4 |
|
5 |
| -## For projects that cannot use package references such as vcxproj. Usage in `Directory.Packages.Props` |
6 |
| -In your global.json add the following: |
7 |
| -```json |
8 |
| -{ |
9 |
| - "msbuild-sdks": { |
10 |
| - "Microsoft.Build.RunVSTest": "1.0.0" |
11 |
| - } |
12 |
| -} |
13 |
| -``` |
14 |
| -In your ..vcxproj file |
15 |
| -```xml |
16 |
| -<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
17 |
| -<Sdk Name="Microsoft.Build.RunVSTest"/> |
18 |
| - ... |
19 |
| -</Project> |
20 |
| -``` |
21 |
| - |
22 |
| -## For projects that use packages references. In your `Directory.Packages.props`: |
23 |
| -```xml |
24 |
| -<Project> |
25 |
| -... |
26 |
| - <ItemGroup> |
27 |
| - <PackageVersion Include="Microsoft.Build.RunVSTest" Version="1.0.0" /> |
28 |
| - </ItemGroup> |
29 |
| -</Project> |
30 |
| -``` |
| 5 | +Note: this SDK defers to the built-in test mechanism when using `dotnet` and simply sets `$(UseMSBuildTestInfrastructure)` to `true`. This SDK is primarily intended for scenarios which use msbuild.exe, the Visual Studio flavor of MSBuild. When using `dotnet`, you can already do `dotnet msbuild /t:Build;Test /p:UseMSBuildTestInfrastructure=true` (or set the property in `Directory.Build.props`) to get this behavior. |
31 | 6 |
|
32 |
| -``` |
33 |
| -<Project> |
34 |
| - <ItemGroup> |
35 |
| - <PackageReference Include="Microsoft.Build.RunVSTest" Version="1.0.0" /> |
36 |
| - </ItemGroup> |
37 |
| -</Project> |
38 |
| -``` |
| 7 | +## Usage |
39 | 8 |
|
40 |
| -This example will include the `Microsoft.Build.RunVSTest` task for all NuGet-based projects in your repo. |
| 9 | +In `Directory.Build.props`: |
41 | 10 |
|
42 |
| -## Dirs.proj example |
43 |
| -Use with traversal project |
44 |
| -``` |
45 |
| -<Project Sdk="Microsoft.Build.Traversal"> |
46 |
| - <ItemGroup> |
47 |
| - <ProjectFile Include="ConsoleApp1\ConsoleApp1.csproj" /> |
48 |
| - <ProjectFile Include="CPPUnitTest1\CPPUnitTest1.vcxproj" Test="true" /> |
49 |
| - <ProjectFile Include="CSharpTestProject1\CSharpTestProject1.csproj" Test="true" /> |
50 |
| - <ProjectFile Include="CSharpTestProject2\CSharpTestProject2.csproj" Test="true" /> |
51 |
| - </ItemGroup> |
52 |
| - </Project> |
| 11 | +```xml |
| 12 | + <Sdk Name="Microsoft.Build.RunVSTest" Version="1.0.0" /> |
53 | 13 | ```
|
54 | 14 |
|
55 |
| -## Sln |
56 |
| -``` |
| 15 | +Alternately, if all projects in the repo support packages references, in `Directory.Packages.props`: |
| 16 | +```xml |
57 | 17 | <Project>
|
58 | 18 | <ItemGroup>
|
59 |
| - <PackageReference Include="Microsoft.Build.RunVSTest" Version="1.0.0" /> |
| 19 | + <GlobalPackageReference Include="Microsoft.Build.RunVSTest" Version="1.0.0" /> |
60 | 20 | </ItemGroup>
|
61 | 21 | </Project>
|
62 | 22 | ```
|
63 | 23 |
|
64 |
| -## Example |
65 |
| -To run tests |
| 24 | +Then to run tests: |
66 | 25 | ```
|
67 | 26 | msbuild /t:Test
|
68 | 27 | ```
|
69 | 28 |
|
70 |
| -To build and run tests |
| 29 | +Or build and run tests |
71 | 30 | ```
|
72 | 31 | msbuild /t:Build;Test
|
73 | 32 | ```
|
| 33 | + |
| 34 | +Note that running build and tests together in a single MSBuild invocation can be significantly faster than building and then in serial running tests after. |
| 35 | + |
| 36 | +## Extensibility |
| 37 | + |
| 38 | +Setting the following properties control how the SDK works. |
| 39 | + |
| 40 | +| Property | Description | |
| 41 | +|-------------------------------------|-------------| |
| 42 | +| `VSTestToolExe` | Overrides the exe name for vstest. By default, `vstest.console.exe` is used. | |
| 43 | +| `VSTestToolPath` | Overrides which directory in which to look for the vstest tool. By default, the SDK looks in `%VSINSTALLDIR%\Common7\IDE\CommonExtensions\Microsoft\TestWindow\` | |
| 44 | + |
| 45 | +There are also various properties which map to VSTest.Console [command-line options](https://learn.microsoft.com/en-us/visualstudio/test/vstest-console-options). |
| 46 | + |
| 47 | +| Property | VSTest argument | |
| 48 | +|-------------------------------------|-----------------| |
| 49 | +| `VSTestSetting` | `--settings` | |
| 50 | +| `VSTestTestAdapterPath` | `--testAdapterPath` | |
| 51 | +| `VSTestFramework` | `--framework` | |
| 52 | +| `VSTestPlatform` | `--platform` | |
| 53 | +| `VSTestTestCaseFilter` | `--testCaseFilter` | |
| 54 | +| `VSTestLogger` | `--logger` | |
| 55 | +| `VSTestListTests` | `--listTests` | |
| 56 | +| `VSTestDiag` | `--Diag` | |
| 57 | +| `VSTestResultsDirectory` | `--resultsDirectory` | |
| 58 | +| `VSTestVerbosity` | `--logger:Console;Verbosity=` | |
| 59 | +| `VSTestCollect` | `--collect` | |
| 60 | +| `VSTestBlame` (bool) | `--Blame` | |
| 61 | +| `VSTestBlameCrash` (bool) | `CollectDump` argument for `--Blame` | |
| 62 | +| `VSTestBlameCrashDumpType` | `DumpType` argument for `--Blame` | |
| 63 | +| `VSTestBlameCrashCollectAlways` | `CollectAlways` argument for `--Blame` | |
| 64 | +| `VSTestBlameHang` (bool) | `CollectHangDump` argument for `--Blame` | |
| 65 | +| `VSTestBlameHangDumpType` | `HangDumpType` argument for `--Blame` | |
| 66 | +| `VSTestBlameHangTimeout` | `TestTimeout` argument for `--Blame` | |
| 67 | +| `VSTestTraceDataCollectorDirectoryPath` | `--testAdapterPath` | |
| 68 | +| `VSTestNoLogo` (bool) | `--nologo` | |
| 69 | +| `VSTestArtifactsProcessingMode` (value `collect`) | `--artifactsProcessingMode-collect` | |
| 70 | +| `VSTestSessionCorrelationId` | `--testSessionCorrelationId` | |
0 commit comments