Skip to content

Commit

Permalink
[Current] Update msbuildtools.js with VS 2019 path
Browse files Browse the repository at this point in the history
Fix for #2420 - "Current" edition
  • Loading branch information
marlenecota authored and rozele committed Jun 7, 2019
1 parent 22133db commit c62a072
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions local-cli/runWindows/utils/msbuildtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const shell = require('shelljs');
const Version = require('./version');
const checkRequirements = require('./checkRequirements');

const MSBUILD_VERSIONS = ['15.0', '14.0', '12.0', '4.0'];
const MSBUILD_VERSIONS = ['16.0', '15.0', '14.0', '12.0', '4.0'];

class MSBuildTools {
constructor(version, localPath) {
Expand Down Expand Up @@ -37,12 +37,18 @@ class MSBuildTools {
'/p:AppxBundle=Never'
];

// Set platform toolset for VS2017 (this way we can keep the base sln file working for vs2015)
// Set platform toolset for VS 2017 (this way we can keep the base sln file working for VS 2015)
if (this.version === '15.0') {
args.push('/p:PlatformToolset=v141');
args.push('/p:VisualStudioVersion=15.0');
}

// Set platform toolset for VS 2019
if (this.version === '16.0') {
args.push('/p:PlatformToolset=v142');
args.push('/p:VisualStudioVersion=16.0');
}

if (config) {
Object.keys(config).forEach(function (key) {
args.push(`/p:${key}=${config[key]}`);
Expand All @@ -66,11 +72,17 @@ function checkMSBuildVersion(version) {
let toolsPath = null;
// This path is maintained and VS has promised to keep it valid.
const vsWherePath = path.join(process.env['ProgramFiles(x86)'], '/Microsoft Visual Studio/Installer/vswhere.exe');
// Check if VS 2017 is installed and if true, go there to find MSBuild.

// Check if vswhere is present and try to find MSBuild.
if (fs.existsSync(vsWherePath)) {
const vsPath = child_process.execSync(`"${vsWherePath}" -latest -products * Microsoft.Component.MSBuild -property installationPath`).toString().split(EOL)[0];

// VS 2019 changed path naming convention
const vsVersion = (version == '16.0') ? 'Current' : version;

// look for the specified version of msbuild
const msBuildPath = path.join(vsPath, 'MSBuild', version, 'Bin/MSBuild.exe');
const msBuildPath = path.join(vsPath, 'MSBuild', vsVersion, 'Bin/MSBuild.exe');

toolsPath = fs.existsSync(msBuildPath) ? path.dirname(msBuildPath) : null;
} else {
const query = `reg query HKLM\\SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\${version} /s /v MSBuildToolsPath`;
Expand All @@ -92,7 +104,7 @@ function checkMSBuildVersion(version) {
}

// We found something so return MSBuild Tools.
if (toolsPath){
if (toolsPath) {
console.log(chalk.green(`Found MSBuild v${version} at ${toolsPath}`));
return new MSBuildTools(version, toolsPath);
}
Expand All @@ -103,7 +115,8 @@ function checkMSBuildVersion(version) {

module.exports.findAvailableVersion = function () {
const versions = MSBUILD_VERSIONS.map(checkMSBuildVersion);
const msbuildTools = versions[0] || versions[1] || versions[2] || versions[3];
const msbuildTools = versions.find(Boolean);

if (!msbuildTools) {
throw new Error('MSBuild tools not found');
}
Expand Down

0 comments on commit c62a072

Please sign in to comment.