You've already forked setup-msbuild
mirror of
https://github.com/microsoft/setup-msbuild.git
synced 2026-09-25 11:17:01 +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:
Vendored
+54
-1
@@ -26,13 +26,45 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
const core = __importStar(__nccwpck_require__(484));
|
||||
const exec = __importStar(__nccwpck_require__(236));
|
||||
const fs = __importStar(__nccwpck_require__(896));
|
||||
const os = __importStar(__nccwpck_require__(857));
|
||||
const path = __importStar(__nccwpck_require__(928));
|
||||
const io = __importStar(__nccwpck_require__(994));
|
||||
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
|
||||
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) {
|
||||
if (explicitArch) {
|
||||
return explicitArch;
|
||||
}
|
||||
if (isWindows64Bit &&
|
||||
vsMajorVersion !== undefined &&
|
||||
vsMajorVersion >= exports.MIN_VS_VERSION_FOR_X64) {
|
||||
return 'x64';
|
||||
}
|
||||
return 'x86';
|
||||
}
|
||||
exports.resolveMSBuildArchitecture = resolveMSBuildArchitecture;
|
||||
// Parses the major version number out of a vswhere `installationVersion` string
|
||||
// such as "17.9.34728.123". Returns undefined if it cannot be parsed.
|
||||
function parseMajorVersion(installationVersion) {
|
||||
const match = installationVersion.trim().match(/^(\d+)/);
|
||||
if (!match) {
|
||||
return undefined;
|
||||
}
|
||||
const major = parseInt(match[1], 10);
|
||||
return isNaN(major) ? undefined : major;
|
||||
}
|
||||
exports.parseMajorVersion = parseMajorVersion;
|
||||
// if a specific version of VS is requested
|
||||
let VSWHERE_EXEC = '-products * -requires Microsoft.Component.MSBuild -property installationPath -latest ';
|
||||
if (ALLOW_PRERELEASE === 'true') {
|
||||
@@ -75,6 +107,27 @@ 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
|
||||
if (!MSBUILD_ARCH_INPUT) {
|
||||
let vsMajorVersion;
|
||||
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;
|
||||
}
|
||||
}
|
||||
};
|
||||
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})`);
|
||||
}
|
||||
let foundToolPath = '';
|
||||
const options = {};
|
||||
options.listeners = {
|
||||
|
||||
Reference in New Issue
Block a user