mirror of
https://github.com/microsoft/setup-msbuild.git
synced 2026-11-29 07:00:28 +07:00
Default to auto-detected 64-bit MSBuild on 64-bit hosts (breaking change, v4)
Fixes #88 - msbuild-architecture no longer hardcodes a default of "x86". When the input is left unspecified, the action now auto-detects: it prefers x64 when running on a 64-bit machine and the resolved VS/MSBuild install is 17.0+ (VS 2022+), and falls back to x86 otherwise. An explicit msbuild-architecture value is always respected. - Extracted resolveMSBuildArchitecture()/parseMajorVersion() as pure, exported helpers and added jest tests covering the resolution matrix. - Bumped package.json version to 4.0.0 (breaking change/new major version). - Updated action.yml input description and README (usage examples now reference @v4, new "Breaking Changes in v4" section, and the architecture-selection docs rewritten to describe auto-detection). - Rebuilt dist/index.js via ncc. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
1 parent
ea1f75da7f
commit
fc127f2e68
6 files changed
+215
-14
No files matched your search
+81
-4
@@ -1,6 +1,7 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as exec from '@actions/exec'
|
||||
import * as fs from 'fs'
|
||||
import * as os from 'os'
|
||||
import * as path from 'path'
|
||||
import * as io from '@actions/io'
|
||||
import {ExecOptions} from '@actions/exec/lib/interfaces'
|
||||
@@ -9,13 +10,56 @@ const IS_WINDOWS = process.platform === 'win32'
|
||||
const VS_VERSION = core.getInput('vs-version') || 'latest'
|
||||
const VSWHERE_PATH = core.getInput('vswhere-path')
|
||||
const ALLOW_PRERELEASE = core.getInput('vs-prerelease') || 'false'
|
||||
let MSBUILD_ARCH = core.getInput('msbuild-architecture') || 'x86'
|
||||
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
|
||||
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
|
||||
): string {
|
||||
if (explicitArch) {
|
||||
return explicitArch
|
||||
}
|
||||
|
||||
if (
|
||||
isWindows64Bit &&
|
||||
vsMajorVersion !== undefined &&
|
||||
vsMajorVersion >= MIN_VS_VERSION_FOR_X64
|
||||
) {
|
||||
return 'x64'
|
||||
}
|
||||
|
||||
return 'x86'
|
||||
}
|
||||
|
||||
// Parses the major version number out of a vswhere `installationVersion` string
|
||||
// such as "17.9.34728.123". Returns undefined if it cannot be parsed.
|
||||
export function parseMajorVersion(
|
||||
installationVersion: string
|
||||
): number | undefined {
|
||||
const match = installationVersion.trim().match(/^(\d+)/)
|
||||
if (!match) {
|
||||
return undefined
|
||||
}
|
||||
const major = parseInt(match[1], 10)
|
||||
return isNaN(major) ? undefined : major
|
||||
}
|
||||
|
||||
// if a specific version of VS is requested
|
||||
let VSWHERE_EXEC = '-products * -requires Microsoft.Component.MSBuild -property installationPath -latest '
|
||||
let VSWHERE_EXEC =
|
||||
'-products * -requires Microsoft.Component.MSBuild -property installationPath -latest '
|
||||
if (ALLOW_PRERELEASE === 'true') {
|
||||
VSWHERE_EXEC += ' -prerelease '
|
||||
}
|
||||
VSWHERE_EXEC += ' -prerelease '
|
||||
}
|
||||
|
||||
if (VS_VERSION !== 'latest') {
|
||||
VSWHERE_EXEC += `-version "${VS_VERSION}" `
|
||||
@@ -64,6 +108,39 @@ async function run(): Promise<void> {
|
||||
|
||||
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
|
||||
if (!MSBUILD_ARCH_INPUT) {
|
||||
let vsMajorVersion: number | undefined
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const versionExec = VSWHERE_EXEC.replace(
|
||||
'-property installationPath',
|
||||
'-property installationVersion'
|
||||
)
|
||||
await 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})`
|
||||
)
|
||||
}
|
||||
|
||||
let foundToolPath = ''
|
||||
const options: ExecOptions = {}
|
||||
options.listeners = {
|
||||
|
||||
Reference in new issue
Block a user