Skip to content

Commit 3240393

Browse files
authored
Release Microsoft.Build.RunVSTest (#557)
1 parent fb0a2ba commit 3240393

File tree

3 files changed

+55
-52
lines changed

3 files changed

+55
-52
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ Supports staging artifacts from build outputs.
2929

3030
Enables Copy on Write for faster file copies.
3131

32+
### [Microsoft.Build.RunVSTest](src/RunTests)
33+
[![NuGet](https://img.shields.io/nuget/v/Microsoft.Build.RunVSTest.svg)](https://www.nuget.org/packages/Microsoft.Build.RunVSTest)
34+
[![NuGet](https://img.shields.io/nuget/dt/Microsoft.Build.RunVSTest.svg)](https://www.nuget.org/packages/Microsoft.Build.RunVSTest)
35+
36+
Hooks VSTest to the Test target, allowing running tests concurrently with the build via `msbuild /t:Build;Test`.
37+
3238
## How can I use these SDKs?
3339

3440
When using an MSBuild Project SDK obtained via NuGet (such as the SDKs in this repo) a specific version **must** be specified.

src/RunTests/README.md

+48-51
Original file line numberDiff line numberDiff line change
@@ -2,72 +2,69 @@
22

33
The `Microsoft.Build.RunVSTest` MSBuild SDK adds support for running tests from MSBuild, similarly to how one would use `dotnet test`.
44

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.
316

32-
```
33-
<Project>
34-
<ItemGroup>
35-
<PackageReference Include="Microsoft.Build.RunVSTest" Version="1.0.0" />
36-
</ItemGroup>
37-
</Project>
38-
```
7+
## Usage
398

40-
This example will include the `Microsoft.Build.RunVSTest` task for all NuGet-based projects in your repo.
9+
In `Directory.Build.props`:
4110

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" />
5313
```
5414

55-
## Sln
56-
```
15+
Alternately, if all projects in the repo support packages references, in `Directory.Packages.props`:
16+
```xml
5717
<Project>
5818
<ItemGroup>
59-
<PackageReference Include="Microsoft.Build.RunVSTest" Version="1.0.0" />
19+
<GlobalPackageReference Include="Microsoft.Build.RunVSTest" Version="1.0.0" />
6020
</ItemGroup>
6121
</Project>
6222
```
6323

64-
## Example
65-
To run tests
24+
Then to run tests:
6625
```
6726
msbuild /t:Test
6827
```
6928

70-
To build and run tests
29+
Or build and run tests
7130
```
7231
msbuild /t:Build;Test
7332
```
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` |

src/RunTests/version.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"inherit": false,
2+
"inherit": true,
33
"version": "1.0"
44
}

0 commit comments

Comments
 (0)