Use -latest and -version properly

Fixes #8
This commit is contained in:
Heath Stewart 2020-04-04 10:47:46 -07:00
parent 2f9b9c17d6
commit 80d0deb83b
3 changed files with 8 additions and 12 deletions

View File

@ -9,15 +9,17 @@ You know how handy that 'Visual Studio Developer Command Prompt' is on your loca
``` ```
## Specifying specific versions of Visual Studio ## Specifying specific versions of Visual Studio
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, enter that version number twice as a range. 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 - name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.0.1 uses: microsoft/setup-msbuild@v1.0.1
with: with:
vs-version: [16.4,16.5] 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](https://github.com/microsoft/vswhere/wiki) for more details.
## How does this work? ## How does this work?
This makes use of the vswhere tool which is a tool is 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: This makes use of the vswhere tool which is a tool is 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:

7
dist/index.js vendored
View File

@ -980,11 +980,8 @@ const VS_VERSION = core.getInput('vs-version') || 'latest';
const VSWHERE_PATH = core.getInput('vswhere-path') || const VSWHERE_PATH = core.getInput('vswhere-path') ||
path.join(process.env['ProgramFiles(x86)'], 'Microsoft Visual Studio\\Installer'); path.join(process.env['ProgramFiles(x86)'], 'Microsoft Visual Studio\\Installer');
// if a specific version of VS is requested // if a specific version of VS is requested
let VSWHERE_EXEC = '-products * -requires Microsoft.Component.MSBuild -property installationPath '; let VSWHERE_EXEC = '-products * -requires Microsoft.Component.MSBuild -property installationPath -latest ';
if (VS_VERSION === 'latest') { if (VS_VERSION !== 'latest') {
VSWHERE_EXEC += '-latest ';
}
else {
VSWHERE_EXEC += `-version "${VS_VERSION}" `; VSWHERE_EXEC += `-version "${VS_VERSION}" `;
} }
core.debug(`Execution arguments: ${VSWHERE_EXEC}`); core.debug(`Execution arguments: ${VSWHERE_EXEC}`);

View File

@ -15,11 +15,8 @@ const VSWHERE_PATH =
) )
// if a specific version of VS is requested // if a specific version of VS is requested
let VSWHERE_EXEC = let VSWHERE_EXEC = '-products * -requires Microsoft.Component.MSBuild -property installationPath -latest '
'-products * -requires Microsoft.Component.MSBuild -property installationPath ' if (VS_VERSION !== 'latest') {
if (VS_VERSION === 'latest') {
VSWHERE_EXEC += '-latest '
} else {
VSWHERE_EXEC += `-version "${VS_VERSION}" ` VSWHERE_EXEC += `-version "${VS_VERSION}" `
} }