Files
setup-msbuild/README.md
Chet Husk fc127f2e68 Default to auto-detected 64-bit MSBuild on 64-bit hosts (breaking change, v4)
Fixes #88

- msbuild-architecture no longer hardcodes a default of "x86". When the
  input is left unspecified, the action now auto-detects: it prefers x64
  when running on a 64-bit machine and the resolved VS/MSBuild install is
  17.0+ (VS 2022+), and falls back to x86 otherwise. An explicit
  msbuild-architecture value is always respected.
- Extracted resolveMSBuildArchitecture()/parseMajorVersion() as pure,
  exported helpers and added jest tests covering the resolution matrix.
- Bumped package.json version to 4.0.0 (breaking change/new major version).
- Updated action.yml input description and README (usage examples now
  reference @v4, new "Breaking Changes in v4" section, and the
  architecture-selection docs rewritten to describe auto-detection).
- Rebuilt dist/index.js via ncc.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
2026-09-22 11:15:16 -05:00

6.7 KiB

microsoft/setup-msbuild

This action will help discover where the MSBuild tool is and automatically add it to the PATH environment variables for you so future steps in your Actions workflow can just initiate msbuild commands without knowing the full path.

Important

Please note this tool does NOT add other Visual Studio tools (like VSTest, cl, cmake, or others) to PATH

Breaking Changes in v4

Starting with v4, the default value of msbuild-architecture is no longer always x86. When msbuild-architecture is not explicitly specified, the action now auto-detects the best architecture:

  • x64 when running on a 64-bit machine and the resolved Visual Studio/MSBuild install is version 17.0 or later (Visual Studio 2022+, which ships a native 64-bit MSBuild).
  • x86 otherwise (older Visual Studio versions, or 32-bit hosts), matching the previous behavior.

If you explicitly set msbuild-architecture (e.g. x86, x64, or arm64), that value is always respected and this auto-detection does not apply. If your workflow depends on always getting the 32-bit MSBuild by default, set msbuild-architecture: x86 explicitly.

Example Usage

- name: Add msbuild to PATH
  uses: microsoft/setup-msbuild@v4

- name: Build app for release
  run: msbuild src\YourProjectFile.csproj -t:rebuild -verbosity:diag -property:Configuration=Release

Runners and included software

This action is intended to be used within the GitHub Actions workflows using the model of 'runners' either hosted (provided by GitHub) or self-hosted (provided by you). The version and parameters you specify below are going to be scoped to what software actually exists on the runner image being used. For example, hosted runner images from GitHub typically do NOT have pre-release versions of Visual Studio on them so using vs-prerelease parameter noted below may not have intended effect when using hosted runners. The software included for GitHub-hosted runner images can always be found here: https://github.com/actions/runner-images which also includes information on when/how software on hosted images gets updated.

Optional Parameters

There are a few additional parameters that can be set if you need them. These are optional and should only be set if you know that you need them or what you are doing.

Specifying specific versions of Visual Studio (optional)

You may have a situation where your Actions runner has multiple versions of Visual Studio and you need to find a specific version of the tool. Simply add the vs-version input to specify the range of versions to find. If looking for a specific version, specify the minimum and maximum versions as shown in the example below, which will look for just 16.4.

- name: Add msbuild to PATH
  uses: microsoft/setup-msbuild@v4
  with:
    vs-version: '[16.4,16.5)'

The syntax is the same used for Visual Studio extensions, where square brackets like "[" mean inclusive, and parenthesis like "(" mean exclusive. A comma is always required, but eliding the minimum version looks for all older versions and eliding the maximum version looks for all newer versions. See the vswhere wiki for more details.

Use pre-release versions of Visual Studio (optional)

If you need your Actions runner to target a pre-release version of Visual Studio, simply add the vs-prerelease input. This is necessary if you want to run an action on a virtual environment that contains a pre-release version of Visual Studio or self-hosted images that you may have that also have pre-release versions of Visual Studio installed.

- name: Add msbuild to PATH
  uses: microsoft/setup-msbuild@v4
  with:
    vs-prerelease: true

Specifying MSBuild architecture (optional)

By default (as of v4), the action auto-detects the preferred MSBuild architecture: it uses x64 when running on a 64-bit machine with Visual Studio/MSBuild 17.0 or later installed, and falls back to x86 otherwise. You can override this by explicitly setting the msbuild-architecture input. Valid input values are x86, x64, and arm64. Note that the success of these will rely on the runner OS.

- name: Add msbuild to PATH
  uses: microsoft/setup-msbuild@v4
  with:
    msbuild-architecture: x64

How does this work?

This makes use of the vswhere tool which is a tool delivered by Microsoft to help in identifying Visual Studio installs and various components. This tool is installed on the hosted Windows runners for GitHub Actions. If you are using a self-hosted runner, you either need to make sure vswhere.exe is in your agent's PATH or specify a full path to the location using:

- name: Add msbuild to PATH
  uses: microsoft/setup-msbuild@v4
  with:
    vswhere-path: 'C:\path\to\your\tools\'

Notes on arguments

While the Action enables you to specify a vswhere path as well as a vs-version, these are more advanced options and when using GitHub-hosted runners you should not need these and is recommended you don't specify them as they are optional. Using these require you to fully understand the runner environment, updates to the tools on the runner, and can cause failures if you are out of sync. For GitHub-hosted runners, omitting these arguments is the preferred usage.

Building this repo

As with most GitHub Actions, this requires NodeJS development tools. After installing NodeJS, you can build this by executing:

npm install
npm run build
npm run pack

which will modify/create the /dist folder with the final index.js output

Credits

Thank you to Warren Buckley for being a core contributor to this Action for the benefit of all developers!

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.