How to Use Visual Studio Build Tools on Windows in GitHub Actions
Visual Studio is preinstalled on windows-latest; vswhere finds it and you can add missing components.
Use vswhere to locate the Visual Studio install, then call its tools or import the developer environment. Add missing workloads with the VS installer in a setup step if needed.
Steps
- Run
vswhere -latest -property installationPathto find Visual Studio. - Add
microsoft/setup-msbuildorilammy/msvc-dev-cmdto put build tools on PATH. - Install extra components with the VS installer only if the image lacks them.
Workflow
.github/workflows/ci.yml
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Locate Visual Studio
shell: pwsh
run: |
$vs = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" `
-latest -property installationPath
Write-Host "Visual Studio at $vs"
- uses: microsoft/setup-msbuild@v2
- run: msbuild App.sln /p:Configuration=ReleaseGotchas
- Hosted images already include common C++ and .NET workloads; installing more adds minutes.
vswherelives under the x86 Program Files Installer directory on every hosted image.
Related guides
How to Build a C++ App With MSVC on Windows in GitHub ActionsCompile a C++ project with the MSVC toolchain on a windows-latest runner in GitHub Actions by importing the D…
How to Build a .NET App on Windows in GitHub ActionsBuild and test a .NET application on a windows-latest runner in GitHub Actions with actions/setup-dotnet, dot…