Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for caching test execution #67

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
For more information, see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

## Setup

It is assumed that you are using VS v17.9 or later.

## Building

### Building MSBuildCache
Expand Down
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This project provides plugin implementations for the experimental [MSBuild Proje

## Usage

This feature requires Visual Studio 17.9 or later.

To enable caching, simply add a `<PackageReference>` for the desired cache implementation and set various properties to configure it.

For repos which build C# code, add a `<PackageReference>` to `Microsoft.MSBuildCache.SharedCompilation` for shared compilation support.
Expand Down Expand Up @@ -78,6 +80,28 @@ When configuring settings which are list types, you should always append to the
</PropertyGroup>
```

### Execution cached builds

Once configured, to execute builds with caching, simply run:

```
msbuild /graph /m /reportfileaccesses
```

It's also recommended to set some parameters like `/p:MSBuildCacheLogDirectory=$(LogDirectory)\MSBuildCache` as part of the MSBuild call, as opposed to with MSBuild properties in your `Directory.Build.props` for example.

### Caching test execution

Arbitrary MSBuild targets can be cached, and with [`Microsoft.Build.RunVSTest`](https://github.com/microsoft/MSBuildSdks/tree/main/src/RunTests), you can attach running vstest-based unit tests with the "Test" target.

Once `Microsoft.Build.RunVSTest`, or some other target hooked to the Test target, you can get cache hits for tests by adding (`/t:Build;Test`), eg:

```
msbuild /graph /m /reportfileaccesses /t:Build;Test
```

This not only provides the benefits of caching unit test execution, but also executes tests concurrently with other, unrelated, projects in the graph.

## Plugins

### Microsoft.MSBuildCache.AzurePipelines
Expand All @@ -103,7 +127,7 @@ It is expected that this plugin is used within an Azure Pipeline. The `SYSTEM_AC
[![NuGet Version](https://img.shields.io/nuget/v/Microsoft.MSBuildCache.Local.svg)](https://www.nuget.org/packages/Microsoft.MSBuildCache.Local)
[![NuGet Downloads](https://img.shields.io/nuget/dt/Microsoft.MSBuildCache.Local.svg)](https://www.nuget.org/packages/Microsoft.MSBuildCache.Local)

This implementation uses the local file system for the cache. In particular, it uses [BuildXL](https://github.com/microsoft/BuildXL)'s `LocalCache`. This is recommended for locally testing and debugging caching for your repo.
This implementation uses the local file system for the cache. In particular, it uses [BuildXL](https://github.com/microsoft/BuildXL)'s `LocalCache`. This is recommended for locally testing and debugging caching for your repo. This implementation can also be useful if you have stateful build agents where the cache can be reused across builds.

### Microsoft.MSBuildCache.AzureBlobStorage
[![NuGet Version](https://img.shields.io/nuget/v/Microsoft.MSBuildCache.AzureBlobStorage.svg)](https://www.nuget.org/packages/Microsoft.MSBuildCache.AzureBlobStorage)
Expand Down