Skip to content

Commit dbbae88

Browse files
MikeAlhayekfluffynuts
authored andcommitted
Fix #5
1 parent d0b1cf2 commit dbbae88

File tree

3 files changed

+58
-40
lines changed

3 files changed

+58
-40
lines changed

lib/constants.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = {
88
PLUGIN_NAME: "gulp-msbuild",
99

1010
MSBUILD_VERSIONS: {
11+
<<<<<<< HEAD
1112
1.0: "v1.0.3705",
1213
1.1: "v1.1.4322",
1314
2.0: "v2.0.50727",
@@ -16,6 +17,17 @@ module.exports = {
1617
12.0: "12.0",
1718
14.0: "14.0",
1819
15.0: "15.0"
20+
=======
21+
1.0: 'v1.0.3705',
22+
1.1: 'v1.1.4322',
23+
2.0: 'v2.0.50727',
24+
3.5: 'v3.5',
25+
4.0: 'v4.0.30319',
26+
12.0: '12.0',
27+
14.0: '14.0',
28+
15.0: '15.0',
29+
16.0: '16.0'
30+
>>>>>>> 8dd0787... Fix #5 for VisualStudio 2019 MBBuild 16
1931
},
2032

2133
DEFAULTS: {

lib/msbuild-finder.js

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,36 @@ function msBuildFromWhere(pathRoot) {
3535
}
3636
}
3737
const installKeyword = "installationPath";
38+
const installationVersionKeyword = "installationVersion";
3839
if (cmdOutput.length > 0) {
40+
let installationPath = "";
41+
let instalationVersion = 15.0;
42+
3943
const results = cmdOutput.split(/\r?\n/);
4044
for (let cmdLineIndex = 0; cmdLineIndex < results.length; cmdLineIndex++) {
4145
const cmdLine = results[cmdLineIndex];
4246
if (cmdLine.startsWith(installKeyword)) {
43-
const match = cmdLine.replace(installKeyword + ": ", "");
44-
return match;
47+
installationPath = cmdLine.replace(installKeyword + ": ", "");
48+
}
49+
50+
if (cmdLine.startsWith(installationVersionKeyword)) {
51+
let versionParts = cmdLine.replace(installationVersionKeyword + ": ", "").split(".");
52+
if(versionParts.length > 0){
53+
instalationVersion = parseFloat(versionParts[0]);
54+
}
4555
}
4656
}
57+
58+
return [installationPath, instalationVersion];
4759
}
48-
return "";
60+
61+
return [];
4962
}
5063

5164
module.exports.msBuildFromWhere = msBuildFromWhere;
5265

5366
function detectMsBuild15Dir (pathRoot) {
54-
const wherePath = msBuildFromWhere(pathRoot) || "";
55-
if (wherePath.length > 0) {
56-
return wherePath;
57-
}
67+
5868
const vs2017Path = path.join(pathRoot, "Microsoft Visual Studio", "2017");
5969
const possibleFolders = [ "BuildTools", "Enterprise", "Professional", "Community" ];
6070

@@ -132,6 +142,13 @@ function addDetectedMsBuildVersionsToConstantsLookup(executables) {
132142
}
133143

134144
function autoDetectVersion (pathRoot) {
145+
146+
// Try to detect using fromWhere
147+
const wherePath = msBuildFromWhere(pathRoot) || "";
148+
if (wherePath.length > 0) {
149+
return wherePath;
150+
}
151+
135152
// Try to detect MSBuild 15.0.
136153
const msbuild15OrLaterDir = detectMsBuild15Dir(pathRoot);
137154
if (msbuild15OrLaterDir) {
@@ -186,53 +203,42 @@ module.exports.find = function (options) {
186203
return "xbuild";
187204
}
188205

189-
let msbuildRoot;
190206
const is64Bit = options.architecture === "x64";
191207

192208
// On 64-bit systems msbuild is always under the x86 directory. If this
193209
// doesn"t exist we are on a 32-bit system. See also:
194210
// https://blogs.msdn.microsoft.com/visualstudio/2013/07/24/msbuild-is-now-part-of-visual-studio/
195-
let pathRoot;
211+
let pathRoot = process.env["ProgramFiles"] || "C:/Program Files";
196212
if (is64Bit) {
197213
pathRoot = process.env["ProgramFiles(x86)"] || "C:/Program Files (x86)";
198-
} else {
199-
pathRoot = process.env["ProgramFiles"] || "C:/Program Files";
200214
}
201215

202-
let major;
203-
// auto-detection also registers higher msbuild versions which from 2019+
204-
let shouldProbe = options.toolsVersion === "auto";
205-
if (options.toolsVersion !== "auto") {
206-
major = parseInt(("" + options.toolsVersion).split(".")[0]);
207-
if (!isNaN(major) && major > 15) {
208-
shouldProbe = true;
209-
}
210-
}
211-
const auto = shouldProbe ? autoDetectVersion(pathRoot) : null;
212-
if (options.toolsVersion === "auto") {
213-
// var result = autoDetectVersion(pathRoot);
214-
msbuildRoot = auto[0]
215-
options.toolsVersion = auto[1];
216+
let msbuildRoot = pathRoot;
217+
let toolsVersion = parseFloat(options.toolsVersion);
218+
219+
if (options.toolsVersion === "auto" || isNaN(toolsVersion)) {
220+
// if the toolsVersion is 'auto' or any other non-parsable string
221+
// we'll auto delect the version
222+
const auto = autoDetectVersion(pathRoot);
223+
msbuildRoot = auto[0];
224+
toolsVersion = parseFloat(auto[1]);
225+
options.toolsVersion = toolsVersion;
216226
} else {
217227
const msbuildDir = detectMsBuild15Dir(pathRoot);
218-
if (options.toolsVersion >= 15.0) {
219-
if (msbuildDir) {
228+
if (msbuildDir && toolsVersion >= 15.0) {
220229
msbuildRoot = msbuildDir;
221-
} else {
222-
msbuildRoot = pathRoot;
223-
}
224-
} else {
225-
msbuildRoot = pathRoot;
226230
}
227231
}
228232

229-
const version = constants.MSBUILD_VERSIONS[options.toolsVersion];
233+
const version = constants.MSBUILD_VERSIONS[toolsVersion];
230234
if (!version) {
231-
throw new PluginError(constants.PLUGIN_NAME, "No MSBuild Version was supplied!");
235+
throw new PluginError(constants.PLUGIN_NAME, "No or invalid MSBuild version was supplied! Please set or check the value of the 'toolsVersion' property.");
232236
}
233237

234-
major = parseInt(version.split(".")[0]);
235-
if (major > 15) {
238+
let major = parseInt(version.split(".")[0]);
239+
if(major >= 16) {
240+
return path.join(msbuildRoot, "MSBuild", "Current", "Bin", "MSBuild.exe");
241+
} else if (major > 15 && major < 16) {
236242
let x64_dir = is64Bit ? "amd64" : "";
237243
const msbuildHome = path.join(msbuildRoot, "MSBuild");
238244
const msbuildExe = findMSBuildExeUnder(msbuildHome)
@@ -251,8 +257,8 @@ module.exports.find = function (options) {
251257
} else if (major >= 12 && major <= 15) {
252258
let x64_dir = is64Bit ? "amd64" : "";
253259
return path.join(msbuildRoot, "MSBuild", version, "Bin", x64_dir, "MSBuild.exe");
254-
} else {
255-
const framework = is64Bit ? "Framework64" : "Framework";
256-
return path.join(options.windir, "Microsoft.Net", framework, version, "MSBuild.exe");
257260
}
261+
262+
const framework = is64Bit ? "Framework64" : "Framework";
263+
return path.join(options.windir, "Microsoft.Net", framework, version, "MSBuild.exe");
258264
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@
6464
"npm": ">=1.2.10"
6565
},
6666
"license": "MIT"
67-
}
67+
}

0 commit comments

Comments
 (0)