diff --git a/README.md b/README.md index afecd4d..648cc1c 100644 --- a/README.md +++ b/README.md @@ -7,17 +7,16 @@ This action will help discover where the `MSBuild` tool is and automatically add ## Breaking Changes in v4 -Starting with `v4`, the default value of `msbuild-architecture` is no longer always `x86`. When -`msbuild-architecture` is not explicitly specified, the action now **auto-detects** the best -architecture: +Starting with `v4`, the default MSBuild architecture is no longer always `x86`. +If `msbuild-architecture` is not set, the action selects an architecture as follows: -- `x64` when running on a 64-bit machine **and** the resolved Visual Studio/MSBuild install is - version 17.0 or later (Visual Studio 2022+, which ships a native 64-bit MSBuild). -- `x86` otherwise (older Visual Studio versions, or 32-bit hosts), matching the previous behavior. +- On an ARM64 runner with Visual Studio 17.0 or later, use `arm64` if it is installed. + Otherwise, use `x64` if it is installed, or `x86`. +- On an x64 runner with Visual Studio 17.0 or later, use `x64`. +- Otherwise, use `x86`. -If you explicitly set `msbuild-architecture` (e.g. `x86`, `x64`, or `arm64`), that value is always -respected and this auto-detection does not apply. If your workflow depends on always getting the -32-bit MSBuild by default, set `msbuild-architecture: x86` explicitly. +The action always uses an explicit `msbuild-architecture` value. +To keep the previous default, set `msbuild-architecture: x86`. ## Example Usage @@ -63,11 +62,10 @@ If you need your Actions runner to target a pre-release version of Visual Studio ### Specifying MSBuild architecture (optional) -By default (as of `v4`), the action auto-detects the preferred MSBuild architecture: it uses `x64` -when running on a 64-bit machine with Visual Studio/MSBuild 17.0 or later installed, and falls back -to `x86` otherwise. You can override this by explicitly setting the `msbuild-architecture` input. -Valid input values are `x86`, `x64`, and `arm64`. Note that the success of these will rely on the -runner OS. +By default, the action selects the MSBuild architecture as described in +[Breaking Changes in v4](#breaking-changes-in-v4). +To override the default, set `msbuild-architecture` to `x86`, `x64`, or `arm64`. +The selected architecture must be installed and supported by the runner. ```yml - name: Add msbuild to PATH diff --git a/__tests__/action.test.ts b/__tests__/action.test.ts new file mode 100644 index 0000000..74c6f02 --- /dev/null +++ b/__tests__/action.test.ts @@ -0,0 +1,194 @@ +import * as path from 'path' +import {ExecOptions} from '@actions/exec/lib/interfaces' + +const installationPath = 'visual-studio' +const arm64Path = path.join( + installationPath, + 'MSBuild\\Current\\Bin\\arm64\\MSBuild.exe' +) +const x64Path = path.join( + installationPath, + 'MSBuild\\Current\\Bin\\amd64\\MSBuild.exe' +) +const x86Path = path.join( + installationPath, + 'MSBuild\\Current\\Bin\\MSBuild.exe' +) + +async function runAction( + files: string[], + explicitArch = '', + version = '17.4.0.0', + nativeArchOverride = '' +): Promise<{ + addedPath: jest.Mock + failed: jest.Mock + exec: jest.Mock +}> { + const platform = Object.getOwnPropertyDescriptor(process, 'platform') + const runnerArch = process.env['RUNNER_ARCH'] + const nativeArch = process.env['PROCESSOR_ARCHITEW6432'] + let finish: () => void = () => {} + const finished = new Promise(resolve => { + finish = resolve + }) + const addedPath = jest.fn(() => finish()) + const failed = jest.fn(() => finish()) + const exec = jest.fn( + async (command: string, _args: string[], options: ExecOptions) => { + const stdout = options.listeners && options.listeners.stdout + if (!stdout) { + throw new Error('Missing stdout listener') + } + if (command.includes('installationVersion')) { + stdout(Buffer.from(version.slice(0, 3))) + stdout(Buffer.from(`${version.slice(3)}\n`)) + } else if (command.includes('installationPath')) { + stdout(Buffer.from('visual-')) + stdout(Buffer.from('studio\n')) + } else { + stdout(Buffer.from('17.4.0\n')) + } + return 0 + } + ) + + try { + Object.defineProperty(process, 'platform', {value: 'win32'}) + process.env['RUNNER_ARCH'] = nativeArchOverride ? 'X86' : 'ARM64' + if (nativeArchOverride) { + process.env['PROCESSOR_ARCHITEW6432'] = nativeArchOverride + } else { + delete process.env['PROCESSOR_ARCHITEW6432'] + } + jest.resetModules() + jest.doMock('@actions/core', () => ({ + getInput: (name: string) => + name === 'msbuild-architecture' ? explicitArch : '', + debug: jest.fn(), + info: jest.fn(), + setFailed: failed, + setOutput: jest.fn(), + addPath: addedPath + })) + jest.doMock('@actions/exec', () => ({exec})) + jest.doMock('@actions/io', () => ({ + which: jest.fn().mockResolvedValue('vswhere.exe') + })) + jest.doMock('os', () => ({arch: () => 'x64'})) + jest.doMock('fs', () => ({ + existsSync: (file: string) => + file === 'vswhere.exe' || files.includes(file) + })) + + require('../src/main') + await finished + return {addedPath, failed, exec} + } finally { + if (platform) { + Object.defineProperty(process, 'platform', platform) + } + if (runnerArch === undefined) { + delete process.env['RUNNER_ARCH'] + } else { + process.env['RUNNER_ARCH'] = runnerArch + } + if (nativeArch === undefined) { + delete process.env['PROCESSOR_ARCHITEW6432'] + } else { + process.env['PROCESSOR_ARCHITEW6432'] = nativeArch + } + jest.resetModules() + } +} + +describe('ARM64 action selection', () => { + it('uses native ARM64 even when Node runs as x64', async () => { + const result = await runAction([arm64Path, x64Path, x86Path]) + + expect(result.failed).not.toHaveBeenCalled() + expect(result.addedPath).toHaveBeenCalledWith(path.dirname(arm64Path)) + expect(result.exec).toHaveBeenCalledWith( + `"${arm64Path}" -version -nologo`, + [], + expect.anything() + ) + }) + + it('uses the native Windows architecture when a 32-bit runner is emulated', async () => { + const result = await runAction( + [arm64Path, x86Path], + '', + '17.4.0.0', + 'ARM64' + ) + + expect(result.failed).not.toHaveBeenCalled() + expect(result.addedPath).toHaveBeenCalledWith(path.dirname(arm64Path)) + expect(result.exec).toHaveBeenCalledWith( + `"${arm64Path}" -version -nologo`, + [], + expect.anything() + ) + }) + + it('falls back to the installed x64 MSBuild', async () => { + const result = await runAction([x64Path, x86Path]) + + expect(result.failed).not.toHaveBeenCalled() + expect(result.addedPath).toHaveBeenCalledWith(path.dirname(x64Path)) + expect(result.exec).toHaveBeenCalledWith( + `"${x64Path}" -version -nologo`, + [], + expect.anything() + ) + }) + + it('falls back to x86 when neither 64-bit executable is installed', async () => { + const result = await runAction([x86Path]) + + expect(result.failed).not.toHaveBeenCalled() + expect(result.addedPath).toHaveBeenCalledWith(path.dirname(x86Path)) + expect(result.exec).toHaveBeenCalledWith( + `"${x86Path}" -version -nologo`, + [], + expect.anything() + ) + }) + + it('uses x86 for Visual Studio versions older than 17', async () => { + const result = await runAction([arm64Path, x86Path], '', '16.11.0.0') + + expect(result.failed).not.toHaveBeenCalled() + expect(result.addedPath).toHaveBeenCalledWith(path.dirname(x86Path)) + expect(result.exec).toHaveBeenCalledWith( + `"${x86Path}" -version -nologo`, + [], + expect.anything() + ) + }) + + it('respects explicit x86 without querying the version', async () => { + const result = await runAction([arm64Path, x86Path], 'x86') + + expect(result.failed).not.toHaveBeenCalled() + expect(result.addedPath).toHaveBeenCalledWith(path.dirname(x86Path)) + expect(result.exec).toHaveBeenCalledWith( + `"${x86Path}" -version -nologo`, + [], + expect.anything() + ) + expect( + result.exec.mock.calls.some(call => + call[0].includes('installationVersion') + ) + ).toBe(false) + }) + + it('does not fall back when an explicit ARM64 executable is missing', async () => { + const result = await runAction([x64Path, x86Path], 'arm64') + + expect(result.addedPath).not.toHaveBeenCalled() + expect(result.failed).toHaveBeenCalledWith('Unable to find MSBuild.') + }) +}) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 742c75e..6bba143 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -1,8 +1,10 @@ -import { - MIN_VS_VERSION_FOR_X64, - parseMajorVersion, - resolveMSBuildArchitecture -} from '../src/main' +import {parseMajorVersion, resolveMSBuildArchitecture} from '../src/main' + +jest.mock('@actions/core', () => ({ + getInput: jest.fn().mockReturnValue(''), + debug: jest.fn(), + setFailed: jest.fn() +})) describe('parseMajorVersion', () => { it('parses a standard installationVersion string', () => { @@ -28,27 +30,46 @@ describe('parseMajorVersion', () => { describe('resolveMSBuildArchitecture', () => { it('always respects an explicit architecture, regardless of OS/version', () => { - expect(resolveMSBuildArchitecture('x86', true, 17)).toBe('x86') - expect(resolveMSBuildArchitecture('x64', false, 15)).toBe('x64') - expect(resolveMSBuildArchitecture('arm64', true, 17)).toBe('arm64') - }) - - it('defaults to x64 on a 64-bit host with VS/MSBuild 17+', () => { - expect(resolveMSBuildArchitecture('', true, MIN_VS_VERSION_FOR_X64)).toBe( + expect(resolveMSBuildArchitecture('x86', 'arm64', 17, true, true)).toBe( + 'x86' + ) + expect(resolveMSBuildArchitecture('x64', 'ia32', 15, false, false)).toBe( 'x64' ) - expect(resolveMSBuildArchitecture('', true, 18)).toBe('x64') + expect(resolveMSBuildArchitecture('arm64', 'x64', 16, false, false)).toBe( + 'arm64' + ) }) - it('defaults to x86 on a 64-bit host with VS/MSBuild older than 17', () => { - expect(resolveMSBuildArchitecture('', true, 16)).toBe('x86') + it('defaults to x64 on an x64 host with VS 17 or later', () => { + expect(resolveMSBuildArchitecture('', 'x64', 17, false, false)).toBe('x64') + expect(resolveMSBuildArchitecture('', 'amd64', 18, false, false)).toBe( + 'x64' + ) }) - it('defaults to x86 on a non-64-bit host even with VS/MSBuild 17+', () => { - expect(resolveMSBuildArchitecture('', false, 17)).toBe('x86') + it('prefers native ARM64 when it is available', () => { + expect(resolveMSBuildArchitecture('', 'arm64', 17, true, true)).toBe( + 'arm64' + ) + }) + + it('falls back to x64 and then x86 when ARM64 MSBuild is unavailable', () => { + expect(resolveMSBuildArchitecture('', 'arm64', 17, false, true)).toBe('x64') + expect(resolveMSBuildArchitecture('', 'arm64', 17, false, false)).toBe( + 'x86' + ) + }) + + it('defaults to x86 for older versions and 32-bit hosts', () => { + expect(resolveMSBuildArchitecture('', 'arm64', 16, true, true)).toBe('x86') + expect(resolveMSBuildArchitecture('', 'x64', 16, false, false)).toBe('x86') + expect(resolveMSBuildArchitecture('', 'ia32', 17, false, false)).toBe('x86') }) it('defaults to x86 when the VS/MSBuild version could not be determined', () => { - expect(resolveMSBuildArchitecture('', true, undefined)).toBe('x86') + expect(resolveMSBuildArchitecture('', 'arm64', undefined, true, true)).toBe( + 'x86' + ) }) }) diff --git a/action.yml b/action.yml index b25fa8c..0590a95 100644 --- a/action.yml +++ b/action.yml @@ -15,7 +15,7 @@ inputs: description: "Enable searching for pre-release versions of Visual Studio/MSBuild" required: false msbuild-architecture: - description: 'The preferred processor architecture of MSBuild. Can be either "x86", "x64", or "arm64". If left unspecified, the action auto-detects the best option: "x64" on 64-bit machines, otherwise "x86".' + description: 'The MSBuild architecture: "x86", "x64", or "arm64". If unspecified with Visual Studio 17 or later, ARM64 runners use arm64 if installed, then x64 if installed, otherwise x86; x64 runners use x64. All other cases use x86.' required: false outputs: msbuildPath: diff --git a/dist/index.js b/dist/index.js index 7a2873a..2caa79d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -35,20 +35,22 @@ const VSWHERE_PATH = core.getInput('vswhere-path'); const ALLOW_PRERELEASE = core.getInput('vs-prerelease') || 'false'; const MSBUILD_ARCH_INPUT = core.getInput('msbuild-architecture'); let MSBUILD_ARCH = MSBUILD_ARCH_INPUT; -// The minimum Visual Studio/MSBuild major version that ships a native x64 MSBuild.exe +// The minimum Visual Studio version for the v4 automatic 64-bit default. exports.MIN_VS_VERSION_FOR_X64 = 17; -// Determines the effective MSBuild architecture to use. -// If the user explicitly specified `msbuild-architecture`, that choice is always respected. -// Otherwise (breaking change as of v4), the action auto-detects and prefers x64 when -// running on a 64-bit OS and the resolved VS/MSBuild installation is version 17.0 or later. -// If the VS version can't be determined, or the host isn't 64-bit, it falls back to x86. -function resolveMSBuildArchitecture(explicitArch, isWindows64Bit, vsMajorVersion) { +function resolveMSBuildArchitecture(explicitArch, hostArch, vsMajorVersion, arm64Available, x64Available) { if (explicitArch) { return explicitArch; } - if (isWindows64Bit && - vsMajorVersion !== undefined && - vsMajorVersion >= exports.MIN_VS_VERSION_FOR_X64) { + if (vsMajorVersion === undefined || vsMajorVersion < exports.MIN_VS_VERSION_FOR_X64) { + return 'x86'; + } + if (hostArch === 'arm64') { + if (arm64Available) { + return 'arm64'; + } + return x64Available ? 'x64' : 'x86'; + } + if (hostArch === 'x64' || hostArch === 'amd64') { return 'x64'; } return 'x86'; @@ -107,62 +109,73 @@ function run() { return; } core.debug(`Full tool exe: ${vswhereToolExe}`); - // if the user did not explicitly specify an architecture, auto-detect the - // preferred architecture based on the host OS and the resolved VS/MSBuild version + let vsMajorVersion; if (!MSBUILD_ARCH_INPUT) { - let vsMajorVersion; + let installationVersion = ''; const versionOptions = {}; versionOptions.listeners = { stdout: (data) => { - const installationVersion = data.toString().trim(); - core.debug(`Found installation version: ${installationVersion}`); - const parsed = parseMajorVersion(installationVersion); - if (parsed !== undefined) { - vsMajorVersion = parsed; - } + installationVersion += data.toString(); } }; const versionExec = VSWHERE_EXEC.replace('-property installationPath', '-property installationVersion'); yield exec.exec(`"${vswhereToolExe}" ${versionExec}`, [], versionOptions); - const isWindows64Bit = os.arch() === 'x64' || os.arch() === 'arm64'; - MSBUILD_ARCH = resolveMSBuildArchitecture(MSBUILD_ARCH_INPUT, isWindows64Bit, vsMajorVersion); - core.info(`Auto-detected msbuild-architecture: ${MSBUILD_ARCH} (os.arch=${os.arch()}, vsMajorVersion=${vsMajorVersion})`); + core.debug(`Found installation version: ${installationVersion.trim()}`); + vsMajorVersion = parseMajorVersion(installationVersion); } - let foundToolPath = ''; + let installationPath = ''; const options = {}; options.listeners = { stdout: (data) => { - const installationPath = data.toString().trim(); - core.debug(`Found installation path: ${installationPath}`); - // x64 and arm64 only exist in one possible location, so no fallback probing - if (MSBUILD_ARCH === 'x64' || MSBUILD_ARCH === 'arm64') { - // x64 is actually amd64 so change to that - if (MSBUILD_ARCH === 'x64') { - MSBUILD_ARCH = 'amd64'; - } - let toolPath = path.join(installationPath, `MSBuild\\Current\\Bin\\${MSBUILD_ARCH}\\MSBuild.exe`); - core.debug(`Checking for path: ${toolPath}`); - if (!fs.existsSync(toolPath)) { - return; - } - foundToolPath = toolPath; - } - else { - 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; - } + installationPath += data.toString(); } }; - // execute the find putting the result of the command in the options foundToolPath yield exec.exec(`"${vswhereToolExe}" ${VSWHERE_EXEC}`, [], options); + installationPath = installationPath.trim(); + core.debug(`Found installation path: ${installationPath}`); + if (!installationPath) { + core.setFailed('Unable to find MSBuild.'); + return; + } + if (!MSBUILD_ARCH_INPUT) { + // os.arch() describes Node, which can run under emulation on Windows. + const hostArch = (process.env['PROCESSOR_ARCHITEW6432'] || + process.env['RUNNER_ARCH'] || + os.arch()).toLowerCase(); + const arm64Available = hostArch === 'arm64' && + fs.existsSync(path.join(installationPath, 'MSBuild\\Current\\Bin\\arm64\\MSBuild.exe')); + const x64Available = hostArch === 'arm64' && + !arm64Available && + fs.existsSync(path.join(installationPath, 'MSBuild\\Current\\Bin\\amd64\\MSBuild.exe')); + MSBUILD_ARCH = resolveMSBuildArchitecture(MSBUILD_ARCH_INPUT, hostArch, vsMajorVersion, arm64Available, x64Available); + if (hostArch === 'arm64' && + vsMajorVersion !== undefined && + vsMajorVersion >= exports.MIN_VS_VERSION_FOR_X64 && + !arm64Available) { + core.info(`ARM64 MSBuild not found; using ${MSBUILD_ARCH} instead`); + } + core.info(`Auto-detected msbuild-architecture: ${MSBUILD_ARCH} (host architecture=${hostArch}, vsMajorVersion=${vsMajorVersion})`); + } + let foundToolPath = ''; + if (MSBUILD_ARCH === 'x64' || MSBUILD_ARCH === 'arm64') { + const directory = MSBUILD_ARCH === 'x64' ? 'amd64' : 'arm64'; + const toolPath = path.join(installationPath, `MSBuild\\Current\\Bin\\${directory}\\MSBuild.exe`); + core.debug(`Checking for path: ${toolPath}`); + if (fs.existsSync(toolPath)) { + foundToolPath = toolPath; + } + } + else { + 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)) { + foundToolPath = toolPath; + } + } if (!foundToolPath) { core.setFailed('Unable to find MSBuild.'); return; diff --git a/src/main.ts b/src/main.ts index 4241034..fd6b19c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -13,28 +13,32 @@ const ALLOW_PRERELEASE = core.getInput('vs-prerelease') || 'false' const MSBUILD_ARCH_INPUT = core.getInput('msbuild-architecture') let MSBUILD_ARCH = MSBUILD_ARCH_INPUT -// The minimum Visual Studio/MSBuild major version that ships a native x64 MSBuild.exe +// The minimum Visual Studio version for the v4 automatic 64-bit default. export const MIN_VS_VERSION_FOR_X64 = 17 -// Determines the effective MSBuild architecture to use. -// If the user explicitly specified `msbuild-architecture`, that choice is always respected. -// Otherwise (breaking change as of v4), the action auto-detects and prefers x64 when -// running on a 64-bit OS and the resolved VS/MSBuild installation is version 17.0 or later. -// If the VS version can't be determined, or the host isn't 64-bit, it falls back to x86. export function resolveMSBuildArchitecture( explicitArch: string, - isWindows64Bit: boolean, - vsMajorVersion: number | undefined + hostArch: string, + vsMajorVersion: number | undefined, + arm64Available: boolean, + x64Available: boolean ): string { if (explicitArch) { return explicitArch } - if ( - isWindows64Bit && - vsMajorVersion !== undefined && - vsMajorVersion >= MIN_VS_VERSION_FOR_X64 - ) { + if (vsMajorVersion === undefined || vsMajorVersion < MIN_VS_VERSION_FOR_X64) { + return 'x86' + } + + if (hostArch === 'arm64') { + if (arm64Available) { + return 'arm64' + } + return x64Available ? 'x64' : 'x86' + } + + if (hostArch === 'x64' || hostArch === 'amd64') { return 'x64' } @@ -108,19 +112,13 @@ async function run(): Promise { core.debug(`Full tool exe: ${vswhereToolExe}`) - // if the user did not explicitly specify an architecture, auto-detect the - // preferred architecture based on the host OS and the resolved VS/MSBuild version + let vsMajorVersion: number | undefined if (!MSBUILD_ARCH_INPUT) { - let vsMajorVersion: number | undefined + let installationVersion = '' const versionOptions: ExecOptions = {} versionOptions.listeners = { stdout: (data: Buffer) => { - const installationVersion = data.toString().trim() - core.debug(`Found installation version: ${installationVersion}`) - const parsed = parseMajorVersion(installationVersion) - if (parsed !== undefined) { - vsMajorVersion = parsed - } + installationVersion += data.toString() } } @@ -129,67 +127,99 @@ async function run(): Promise { '-property installationVersion' ) await exec.exec(`"${vswhereToolExe}" ${versionExec}`, [], versionOptions) + core.debug(`Found installation version: ${installationVersion.trim()}`) + vsMajorVersion = parseMajorVersion(installationVersion) + } - const isWindows64Bit = os.arch() === 'x64' || os.arch() === 'arm64' + let installationPath = '' + const options: ExecOptions = {} + options.listeners = { + stdout: (data: Buffer) => { + installationPath += data.toString() + } + } + + await exec.exec(`"${vswhereToolExe}" ${VSWHERE_EXEC}`, [], options) + installationPath = installationPath.trim() + core.debug(`Found installation path: ${installationPath}`) + if (!installationPath) { + core.setFailed('Unable to find MSBuild.') + return + } + + if (!MSBUILD_ARCH_INPUT) { + // os.arch() describes Node, which can run under emulation on Windows. + const hostArch = ( + process.env['PROCESSOR_ARCHITEW6432'] || + process.env['RUNNER_ARCH'] || + os.arch() + ).toLowerCase() + const arm64Available = + hostArch === 'arm64' && + fs.existsSync( + path.join( + installationPath, + 'MSBuild\\Current\\Bin\\arm64\\MSBuild.exe' + ) + ) + const x64Available = + hostArch === 'arm64' && + !arm64Available && + fs.existsSync( + path.join( + installationPath, + 'MSBuild\\Current\\Bin\\amd64\\MSBuild.exe' + ) + ) MSBUILD_ARCH = resolveMSBuildArchitecture( MSBUILD_ARCH_INPUT, - isWindows64Bit, - vsMajorVersion + hostArch, + vsMajorVersion, + arm64Available, + x64Available ) + if ( + hostArch === 'arm64' && + vsMajorVersion !== undefined && + vsMajorVersion >= MIN_VS_VERSION_FOR_X64 && + !arm64Available + ) { + core.info(`ARM64 MSBuild not found; using ${MSBUILD_ARCH} instead`) + } core.info( - `Auto-detected msbuild-architecture: ${MSBUILD_ARCH} (os.arch=${os.arch()}, vsMajorVersion=${vsMajorVersion})` + `Auto-detected msbuild-architecture: ${MSBUILD_ARCH} (host architecture=${hostArch}, vsMajorVersion=${vsMajorVersion})` ) } let foundToolPath = '' - const options: ExecOptions = {} - options.listeners = { - stdout: (data: Buffer) => { - const installationPath = data.toString().trim() - core.debug(`Found installation path: ${installationPath}`) - - // x64 and arm64 only exist in one possible location, so no fallback probing - if (MSBUILD_ARCH === 'x64' || MSBUILD_ARCH === 'arm64') { - // x64 is actually amd64 so change to that - if (MSBUILD_ARCH === 'x64') { - MSBUILD_ARCH = 'amd64' - } - let toolPath = path.join( - installationPath, - `MSBuild\\Current\\Bin\\${MSBUILD_ARCH}\\MSBuild.exe` - ) - core.debug(`Checking for path: ${toolPath}`) - if (!fs.existsSync(toolPath)) { - return - } - foundToolPath = toolPath - } else { - 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 - } + if (MSBUILD_ARCH === 'x64' || MSBUILD_ARCH === 'arm64') { + const directory = MSBUILD_ARCH === 'x64' ? 'amd64' : 'arm64' + const toolPath = path.join( + installationPath, + `MSBuild\\Current\\Bin\\${directory}\\MSBuild.exe` + ) + core.debug(`Checking for path: ${toolPath}`) + if (fs.existsSync(toolPath)) { + foundToolPath = toolPath + } + } else { + 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)) { + foundToolPath = toolPath } } - // execute the find putting the result of the command in the options foundToolPath - await exec.exec(`"${vswhereToolExe}" ${VSWHERE_EXEC}`, [], options) - if (!foundToolPath) { core.setFailed('Unable to find MSBuild.') return