mirror of
https://github.com/microsoft/setup-msbuild.git
synced 2024-11-22 11:31:07 +07:00
Merge branch 'dev' into dependabot/npm_and_yarn/acorn-5.7.4
This commit is contained in:
commit
41a4f5dd79
26
.github/workflows/test.yml
vendored
26
.github/workflows/test.yml
vendored
@ -1,5 +1,10 @@
|
||||
name: "build-test-dev"
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- dev
|
||||
paths-ignore:
|
||||
- '*.md'
|
||||
push:
|
||||
branches:
|
||||
- dev
|
||||
@ -12,14 +17,27 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Setup MSBuild
|
||||
id: setup_msbuild
|
||||
- name: Setup MSBuild (vswhere-path)
|
||||
id: setup_msbuild_explicit
|
||||
uses: ./
|
||||
with:
|
||||
vs-version: "[16.4,16.6]"
|
||||
vswhere-path: C:\ProgramData\chocolatey\bin
|
||||
|
||||
- name: Setup MSBuild (PATH)
|
||||
id: setup_msbuild_path
|
||||
uses: ./
|
||||
|
||||
- name: Setup MSBuild (fallback)
|
||||
id: setup_msbuild_fallback
|
||||
uses: ./
|
||||
env:
|
||||
PATH: ''
|
||||
|
||||
- name: echo msbuild path
|
||||
run: echo "${{ steps.setup_msbuild.outputs.msbuildPath }}"
|
||||
run: |
|
||||
echo "vswhere-path: ${{ steps.setup_msbuild_explicit.outputs.msbuildPath }}"
|
||||
echo "PATH: ${{ steps.setup_msbuild_path.outputs.msbuildPath }}"
|
||||
echo "Fallback: ${{ steps.setup_msbuild_fallback.outputs.msbuildPath }}"
|
||||
|
||||
- name: echo MSBuild
|
||||
run: msbuild -version
|
20
README.md
20
README.md
@ -3,27 +3,29 @@ You know how handy that 'Visual Studio Developer Command Prompt' is on your loca
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
```yml
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/setup-msbuild@v1.0.0
|
||||
uses: microsoft/setup-msbuild@v1.0.1
|
||||
```
|
||||
|
||||
## 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.
|
||||
|
||||
```
|
||||
```yml
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/setup-msbuild@v1.0.0
|
||||
uses: microsoft/setup-msbuild@v1.0.1
|
||||
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?
|
||||
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:
|
||||
|
||||
```
|
||||
```yml
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/setup-msbuild@v1.0.0
|
||||
uses: microsoft/setup-msbuild@v1.0.1
|
||||
with:
|
||||
vswhere-path: 'C:\path\to\your\tools\'
|
||||
```
|
||||
@ -34,7 +36,7 @@ While the Action enables you to specify a `vswhere` path as well as a `vs-versio
|
||||
## Building this repo
|
||||
As with most GitHub Actions, this requires NodeJS development tools. After installing NodeJS, you can build this by executing:
|
||||
|
||||
```
|
||||
```bash
|
||||
npm install
|
||||
npm run build
|
||||
npm run pack
|
||||
|
44
dist/index.js
vendored
44
dist/index.js
vendored
@ -972,22 +972,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(__webpack_require__(470));
|
||||
const exec = __importStar(__webpack_require__(986));
|
||||
const fs = __importStar(__webpack_require__(747));
|
||||
const path = __importStar(__webpack_require__(622));
|
||||
const io = __importStar(__webpack_require__(1));
|
||||
const IS_WINDOWS = process.platform === 'win32';
|
||||
const VS_VERSION = core.getInput('vs-version') || 'latest';
|
||||
const VSWHERE_PATH = core.getInput('vswhere-path') ||
|
||||
path.join(process.env['ProgramFiles(x86)'], 'Microsoft Visual Studio\\Installer');
|
||||
const VSWHERE_PATH = core.getInput('vswhere-path');
|
||||
// if a specific version of VS is requested
|
||||
let VSWHERE_EXEC = '';
|
||||
if (VS_VERSION === 'latest') {
|
||||
VSWHERE_EXEC += '-latest ';
|
||||
let VSWHERE_EXEC = '-products * -requires Microsoft.Component.MSBuild -property installationPath -latest ';
|
||||
if (VS_VERSION !== 'latest') {
|
||||
VSWHERE_EXEC += `-version "${VS_VERSION}" `;
|
||||
}
|
||||
else {
|
||||
VSWHERE_EXEC += `-version ${VS_VERSION} `;
|
||||
}
|
||||
VSWHERE_EXEC +=
|
||||
'-requires Microsoft.Component.MSBuild -find MSBuild\\**\\Bin\\MSBuild.exe';
|
||||
core.debug(`Execution arguments: ${VSWHERE_EXEC}`);
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
@ -1001,6 +996,7 @@ function run() {
|
||||
let vswhereToolExe = '';
|
||||
if (VSWHERE_PATH) {
|
||||
// specified a path for vswhere, use it
|
||||
core.debug(`Using given vswhere-path: ${VSWHERE_PATH}`);
|
||||
vswhereToolExe = path.join(VSWHERE_PATH, 'vswhere.exe');
|
||||
}
|
||||
else {
|
||||
@ -1008,29 +1004,41 @@ function run() {
|
||||
try {
|
||||
const vsWhereInPath = yield io.which('vswhere', true);
|
||||
core.debug(`Found tool in PATH: ${vsWhereInPath}`);
|
||||
vswhereToolExe = path.join(vsWhereInPath, 'vswhere.exe');
|
||||
vswhereToolExe = vsWhereInPath;
|
||||
}
|
||||
catch (_a) {
|
||||
// wasn't found because which threw
|
||||
// fall back to VS-installed path
|
||||
vswhereToolExe = path.join(process.env['ProgramFiles(x86)'], 'Microsoft Visual Studio\\Installer\\vswhere.exe');
|
||||
core.debug(`Trying Visual Studio-installed path: ${vswhereToolExe}`);
|
||||
}
|
||||
finally {
|
||||
}
|
||||
if (!fs.existsSync(vswhereToolExe)) {
|
||||
core.setFailed('setup-msbuild requires the path to where vswhere.exe exists');
|
||||
}
|
||||
return;
|
||||
}
|
||||
core.debug(`Full tool exe: ${vswhereToolExe}`);
|
||||
let foundToolPath = '';
|
||||
const options = {};
|
||||
options.listeners = {
|
||||
stdout: (data) => {
|
||||
// eslint-disable-next-line prefer-const
|
||||
let output = data.toString();
|
||||
foundToolPath += output;
|
||||
const installationPath = data.toString().trim();
|
||||
core.debug(`Found installation path: ${installationPath}`);
|
||||
let toolPath = path.join(installationPath, 'MSBuild\\Current\\Bin\\MSBuild.exe');
|
||||
core.debug(`Checking for path: ${toolPath}`);
|
||||
if (!fs.existsSync(toolPath)) {
|
||||
toolPath = path.join(installationPath, 'MSBuild\\15.0\\Bin\\MSBuild.exe');
|
||||
core.debug(`Checking for path: ${toolPath}`);
|
||||
if (!fs.existsSync(toolPath)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
foundToolPath = toolPath;
|
||||
}
|
||||
};
|
||||
// execute the find putting the result of the command in the options foundToolPath
|
||||
yield exec.exec(`"${vswhereToolExe}" ${VSWHERE_EXEC}`, [], options);
|
||||
if (!foundToolPath) {
|
||||
core.setFailed('Unable to find msbuild.');
|
||||
core.setFailed('Unable to find MSBuild.');
|
||||
return;
|
||||
}
|
||||
// extract the folder location for the tool
|
||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "setup-msbuild",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "setup-msbuild",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"private": true,
|
||||
"description": "Helps set up specific MSBuild tool into PATH for later usage.",
|
||||
"main": "lib/main.js",
|
||||
@ -11,7 +11,7 @@
|
||||
"lint": "eslint src/**/*.ts",
|
||||
"pack": "ncc build",
|
||||
"test": "jest",
|
||||
"all": "npm run build && npm run format && npm run lint && npm run pack && npm test"
|
||||
"all": "npm run build && npm run format && npm run lint && npm run pack"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
63
src/main.ts
63
src/main.ts
@ -1,27 +1,19 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as exec from '@actions/exec'
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import * as io from '@actions/io'
|
||||
import {ExecOptions} from '@actions/exec/lib/interfaces'
|
||||
|
||||
const IS_WINDOWS = process.platform === 'win32'
|
||||
const VS_VERSION = core.getInput('vs-version') || 'latest'
|
||||
const VSWHERE_PATH =
|
||||
core.getInput('vswhere-path') ||
|
||||
path.join(
|
||||
process.env['ProgramFiles(x86)'] as string,
|
||||
'Microsoft Visual Studio\\Installer'
|
||||
)
|
||||
const VSWHERE_PATH = core.getInput('vswhere-path')
|
||||
|
||||
// if a specific version of VS is requested
|
||||
let VSWHERE_EXEC = ''
|
||||
if (VS_VERSION === 'latest') {
|
||||
VSWHERE_EXEC += '-latest '
|
||||
} else {
|
||||
VSWHERE_EXEC += `-version ${VS_VERSION} `
|
||||
let VSWHERE_EXEC = '-products * -requires Microsoft.Component.MSBuild -property installationPath -latest '
|
||||
if (VS_VERSION !== 'latest') {
|
||||
VSWHERE_EXEC += `-version "${VS_VERSION}" `
|
||||
}
|
||||
VSWHERE_EXEC +=
|
||||
'-requires Microsoft.Component.MSBuild -find MSBuild\\**\\Bin\\MSBuild.exe'
|
||||
|
||||
core.debug(`Execution arguments: ${VSWHERE_EXEC}`)
|
||||
|
||||
@ -38,20 +30,30 @@ async function run(): Promise<void> {
|
||||
|
||||
if (VSWHERE_PATH) {
|
||||
// specified a path for vswhere, use it
|
||||
core.debug(`Using given vswhere-path: ${VSWHERE_PATH}`)
|
||||
vswhereToolExe = path.join(VSWHERE_PATH, 'vswhere.exe')
|
||||
} else {
|
||||
// check in PATH to see if it is there
|
||||
try {
|
||||
const vsWhereInPath: string = await io.which('vswhere', true)
|
||||
core.debug(`Found tool in PATH: ${vsWhereInPath}`)
|
||||
vswhereToolExe = path.join(vsWhereInPath, 'vswhere.exe')
|
||||
vswhereToolExe = vsWhereInPath
|
||||
} catch {
|
||||
// wasn't found because which threw
|
||||
} finally {
|
||||
// fall back to VS-installed path
|
||||
vswhereToolExe = path.join(
|
||||
process.env['ProgramFiles(x86)'] as string,
|
||||
'Microsoft Visual Studio\\Installer\\vswhere.exe'
|
||||
)
|
||||
core.debug(`Trying Visual Studio-installed path: ${vswhereToolExe}`)
|
||||
}
|
||||
}
|
||||
|
||||
if (!fs.existsSync(vswhereToolExe)) {
|
||||
core.setFailed(
|
||||
'setup-msbuild requires the path to where vswhere.exe exists'
|
||||
)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
core.debug(`Full tool exe: ${vswhereToolExe}`)
|
||||
@ -60,9 +62,28 @@ async function run(): Promise<void> {
|
||||
const options: ExecOptions = {}
|
||||
options.listeners = {
|
||||
stdout: (data: Buffer) => {
|
||||
// eslint-disable-next-line prefer-const
|
||||
let output = data.toString()
|
||||
foundToolPath += output
|
||||
const installationPath = data.toString().trim()
|
||||
core.debug(`Found installation path: ${installationPath}`)
|
||||
|
||||
let toolPath = path.join(
|
||||
installationPath,
|
||||
'MSBuild\\Current\\Bin\\MSBuild.exe'
|
||||
)
|
||||
|
||||
core.debug(`Checking for path: ${toolPath}`)
|
||||
if (!fs.existsSync(toolPath)) {
|
||||
toolPath = path.join(
|
||||
installationPath,
|
||||
'MSBuild\\15.0\\Bin\\MSBuild.exe'
|
||||
)
|
||||
|
||||
core.debug(`Checking for path: ${toolPath}`)
|
||||
if (!fs.existsSync(toolPath)) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
foundToolPath = toolPath
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,7 +91,7 @@ async function run(): Promise<void> {
|
||||
await exec.exec(`"${vswhereToolExe}" ${VSWHERE_EXEC}`, [], options)
|
||||
|
||||
if (!foundToolPath) {
|
||||
core.setFailed('Unable to find msbuild.')
|
||||
core.setFailed('Unable to find MSBuild.')
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user