MSBuild Server for CLI Caching
When to Use
- Small incremental builds from CLI (
dotnet build) are slower than expected - Developers notice that VS builds are faster than CLI builds for the same project
- CI agents run many sequential builds of the same repo
How It Works
By default, each dotnet build invocation starts a fresh MSBuild process. The MSBuild Server keeps a long-lived process that caches evaluation results, resolved assemblies, and other state across builds — similar to how Visual Studio reuses its MSBuild nodes.
Setup
Set the environment variable:
# Bash / CI
export MSBUILDUSESERVER=1
# PowerShell
$env:MSBUILDUSESERVER = "1"
# Windows (persistent)
setx MSBUILDUSESERVER 1
Expected Impact
- First build: no change (server starts cold)
- Subsequent incremental builds: faster due to cached evaluation, resolved references, and warm JIT
- Most noticeable in repos with many projects or complex
Directory.Build.propschains
Limitations
- The server process persists in the background — uses some memory
- If builds behave unexpectedly, try
dotnet build-server shutdownto reset - Not all MSBuild features are compatible with server mode