Skip to content
Latchkey

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 installationPath to find Visual Studio.
  • Add microsoft/setup-msbuild or ilammy/msvc-dev-cmd to 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=Release

Gotchas

  • Hosted images already include common C++ and .NET workloads; installing more adds minutes.
  • vswhere lives under the x86 Program Files Installer directory on every hosted image.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →