microsoft / setup-msbuild

A GitHub Action to facilitate configuring MSBuild in the workflow PATH for building .NET Framework applications.
MIT License
336 stars 89 forks source link

Specification of `vs-version` fails on `windows-2022` runners #132

Open robbmcleod opened 2 months ago

robbmcleod commented 2 months ago

The documentation suggests that one can select an older version of MSBuild by specifying it in the YAML:

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

However, this does not work on GitHub Actions. vswhere returns no result.

Run microsoft/setup-msbuild@v2
C:\ProgramData\Chocolatey\bin\vswhere.exe -products * -requires Microsoft.Component.MSBuild -property installationPath -latest -version [17.7,17.8)
Error: Unable to find MSBuild.

If we look at the Windows latest config, it seems the problem is likely that no older versions of MSBuild are installed:

https://github.com/actions/runner-images/blob/main/images/windows/toolsets/toolset-2022.json

Is this intended to work only on self-hosted runners? If so the documentation should be more clear.

timheuer commented 2 months ago

Correct, the version you are looking for must exist, or you will hit a failure as indicated. It is not an acquisition argument, it is a path argument really. See: https://github.com/microsoft/setup-msbuild#specifying-specific-versions-of-visual-studio-optional and https://github.com/microsoft/setup-msbuild#notes-on-arguments noting 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.

Any suggestions to make that clearer we are happy to update a remark on the README.

FabienDanieau commented 1 week ago

This configuration was working fine until I've got the same error yesterday.

    - name: Setup MSBuild
      uses: microsoft/setup-msbuild@v2
      with:
        vs-version: '[17.10,17.11)'

Do I have to specific an exact version as listed here https://github.com/dotnet/msbuild/releases ? I tried [17.11.4, 17.12) but it also failed

timheuer commented 1 week ago

@FabienDanieau see what is available on the hosted agent: https://github.com/actions/runner-images/blob/main/images/windows/Windows2022-Readme.md

For hosted you don’t really have an option and will really only have one version so specifying the version isn’t recommended really as noted here: https://github.com/microsoft/setup-msbuild?tab=readme-ov-file#notes-on-arguments