@@ -35,26 +35,36 @@ function msBuildFromWhere(pathRoot) {
35
35
}
36
36
}
37
37
const installKeyword = "installationPath" ;
38
+ const installationVersionKeyword = "installationVersion" ;
38
39
if ( cmdOutput . length > 0 ) {
40
+ let installationPath = "" ;
41
+ let instalationVersion = 15.0 ;
42
+
39
43
const results = cmdOutput . split ( / \r ? \n / ) ;
40
44
for ( let cmdLineIndex = 0 ; cmdLineIndex < results . length ; cmdLineIndex ++ ) {
41
45
const cmdLine = results [ cmdLineIndex ] ;
42
46
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
+ }
45
55
}
46
56
}
57
+
58
+ return [ installationPath , instalationVersion ] ;
47
59
}
48
- return "" ;
60
+
61
+ return [ ] ;
49
62
}
50
63
51
64
module . exports . msBuildFromWhere = msBuildFromWhere ;
52
65
53
66
function detectMsBuild15Dir ( pathRoot ) {
54
- const wherePath = msBuildFromWhere ( pathRoot ) || "" ;
55
- if ( wherePath . length > 0 ) {
56
- return wherePath ;
57
- }
67
+
58
68
const vs2017Path = path . join ( pathRoot , "Microsoft Visual Studio" , "2017" ) ;
59
69
const possibleFolders = [ "BuildTools" , "Enterprise" , "Professional" , "Community" ] ;
60
70
@@ -132,6 +142,13 @@ function addDetectedMsBuildVersionsToConstantsLookup(executables) {
132
142
}
133
143
134
144
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
+
135
152
// Try to detect MSBuild 15.0.
136
153
const msbuild15OrLaterDir = detectMsBuild15Dir ( pathRoot ) ;
137
154
if ( msbuild15OrLaterDir ) {
@@ -186,53 +203,42 @@ module.exports.find = function (options) {
186
203
return "xbuild" ;
187
204
}
188
205
189
- let msbuildRoot ;
190
206
const is64Bit = options . architecture === "x64" ;
191
207
192
208
// On 64-bit systems msbuild is always under the x86 directory. If this
193
209
// doesn"t exist we are on a 32-bit system. See also:
194
210
// 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" ;
196
212
if ( is64Bit ) {
197
213
pathRoot = process . env [ "ProgramFiles(x86)" ] || "C:/Program Files (x86)" ;
198
- } else {
199
- pathRoot = process . env [ "ProgramFiles" ] || "C:/Program Files" ;
200
214
}
201
215
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 ;
216
226
} else {
217
227
const msbuildDir = detectMsBuild15Dir ( pathRoot ) ;
218
- if ( options . toolsVersion >= 15.0 ) {
219
- if ( msbuildDir ) {
228
+ if ( msbuildDir && toolsVersion >= 15.0 ) {
220
229
msbuildRoot = msbuildDir ;
221
- } else {
222
- msbuildRoot = pathRoot ;
223
- }
224
- } else {
225
- msbuildRoot = pathRoot ;
226
230
}
227
231
}
228
232
229
- const version = constants . MSBUILD_VERSIONS [ options . toolsVersion ] ;
233
+ const version = constants . MSBUILD_VERSIONS [ toolsVersion ] ;
230
234
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. " ) ;
232
236
}
233
237
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 ) {
236
242
let x64_dir = is64Bit ? "amd64" : "" ;
237
243
const msbuildHome = path . join ( msbuildRoot , "MSBuild" ) ;
238
244
const msbuildExe = findMSBuildExeUnder ( msbuildHome )
@@ -251,8 +257,8 @@ module.exports.find = function (options) {
251
257
} else if ( major >= 12 && major <= 15 ) {
252
258
let x64_dir = is64Bit ? "amd64" : "" ;
253
259
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" ) ;
257
260
}
261
+
262
+ const framework = is64Bit ? "Framework64" : "Framework" ;
263
+ return path . join ( options . windir , "Microsoft.Net" , framework , version , "MSBuild.exe" ) ;
258
264
} ;
0 commit comments