Skip to content

Commit

Permalink
Release Microsoft.Build.RunVSTest (#557)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfederm authored Apr 1, 2024
1 parent fb0a2ba commit 3240393
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 52 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ Supports staging artifacts from build outputs.

Enables Copy on Write for faster file copies.

### [Microsoft.Build.RunVSTest](src/RunTests)
[![NuGet](https://img.shields.io/nuget/v/Microsoft.Build.RunVSTest.svg)](https://www.nuget.org/packages/Microsoft.Build.RunVSTest)
[![NuGet](https://img.shields.io/nuget/dt/Microsoft.Build.RunVSTest.svg)](https://www.nuget.org/packages/Microsoft.Build.RunVSTest)

Hooks VSTest to the Test target, allowing running tests concurrently with the build via `msbuild /t:Build;Test`.

## How can I use these SDKs?

When using an MSBuild Project SDK obtained via NuGet (such as the SDKs in this repo) a specific version **must** be specified.
Expand Down
99 changes: 48 additions & 51 deletions src/RunTests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,72 +2,69 @@

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

## For projects that cannot use package references such as vcxproj. Usage in `Directory.Packages.Props`
In your global.json add the following:
```json
{
"msbuild-sdks": {
"Microsoft.Build.RunVSTest": "1.0.0"
}
}
```
In your ..vcxproj file
```xml
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Sdk Name="Microsoft.Build.RunVSTest"/>
...
</Project>
```

## For projects that use packages references. In your `Directory.Packages.props`:
```xml
<Project>
...
<ItemGroup>
<PackageVersion Include="Microsoft.Build.RunVSTest" Version="1.0.0" />
</ItemGroup>
</Project>
```
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.

```
<Project>
<ItemGroup>
<PackageReference Include="Microsoft.Build.RunVSTest" Version="1.0.0" />
</ItemGroup>
</Project>
```
## Usage

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

## Dirs.proj example
Use with traversal project
```
<Project Sdk="Microsoft.Build.Traversal">
<ItemGroup>
<ProjectFile Include="ConsoleApp1\ConsoleApp1.csproj" />
<ProjectFile Include="CPPUnitTest1\CPPUnitTest1.vcxproj" Test="true" />
<ProjectFile Include="CSharpTestProject1\CSharpTestProject1.csproj" Test="true" />
<ProjectFile Include="CSharpTestProject2\CSharpTestProject2.csproj" Test="true" />
</ItemGroup>
</Project>
```xml
<Sdk Name="Microsoft.Build.RunVSTest" Version="1.0.0" />
```

## Sln
```
Alternately, if all projects in the repo support packages references, in `Directory.Packages.props`:
```xml
<Project>
<ItemGroup>
<PackageReference Include="Microsoft.Build.RunVSTest" Version="1.0.0" />
<GlobalPackageReference Include="Microsoft.Build.RunVSTest" Version="1.0.0" />
</ItemGroup>
</Project>
```

## Example
To run tests
Then to run tests:
```
msbuild /t:Test
```

To build and run tests
Or build and run tests
```
msbuild /t:Build;Test
```

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.

## Extensibility

Setting the following properties control how the SDK works.

| Property | Description |
|-------------------------------------|-------------|
| `VSTestToolExe` | Overrides the exe name for vstest. By default, `vstest.console.exe` is used. |
| `VSTestToolPath` | Overrides which directory in which to look for the vstest tool. By default, the SDK looks in `%VSINSTALLDIR%\Common7\IDE\CommonExtensions\Microsoft\TestWindow\` |

There are also various properties which map to VSTest.Console [command-line options](https://learn.microsoft.com/en-us/visualstudio/test/vstest-console-options).

| Property | VSTest argument |
|-------------------------------------|-----------------|
| `VSTestSetting` | `--settings` |
| `VSTestTestAdapterPath` | `--testAdapterPath` |
| `VSTestFramework` | `--framework` |
| `VSTestPlatform` | `--platform` |
| `VSTestTestCaseFilter` | `--testCaseFilter` |
| `VSTestLogger` | `--logger` |
| `VSTestListTests` | `--listTests` |
| `VSTestDiag` | `--Diag` |
| `VSTestResultsDirectory` | `--resultsDirectory` |
| `VSTestVerbosity` | `--logger:Console;Verbosity=` |
| `VSTestCollect` | `--collect` |
| `VSTestBlame` (bool) | `--Blame` |
| `VSTestBlameCrash` (bool) | `CollectDump` argument for `--Blame` |
| `VSTestBlameCrashDumpType` | `DumpType` argument for `--Blame` |
| `VSTestBlameCrashCollectAlways` | `CollectAlways` argument for `--Blame` |
| `VSTestBlameHang` (bool) | `CollectHangDump` argument for `--Blame` |
| `VSTestBlameHangDumpType` | `HangDumpType` argument for `--Blame` |
| `VSTestBlameHangTimeout` | `TestTimeout` argument for `--Blame` |
| `VSTestTraceDataCollectorDirectoryPath` | `--testAdapterPath` |
| `VSTestNoLogo` (bool) | `--nologo` |
| `VSTestArtifactsProcessingMode` (value `collect`) | `--artifactsProcessingMode-collect` |
| `VSTestSessionCorrelationId` | `--testSessionCorrelationId` |
2 changes: 1 addition & 1 deletion src/RunTests/version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"inherit": false,
"inherit": true,
"version": "1.0"
}

0 comments on commit 3240393

Please sign in to comment.