Skip to content

Commit 23bd601

Browse files
committed
windows: better msbuild version/path parsing and query correct registry on 64-bit
1 parent 3923b73 commit 23bd601

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

lib/build.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,22 +119,33 @@ function build (gyp, argv, callback) {
119119
function findMsbuild () {
120120
log.verbose('could not find "msbuild.exe" in PATH - finding location in registry')
121121
var notfoundErr = new Error('Can\'t find "msbuild.exe". Do you have Microsoft Visual Studio C++ 2008+ installed?')
122-
exec('reg query "HKLM\\Software\\Microsoft\\MSBuild\\ToolsVersions" /s', function (err, stdout, stderr) {
123-
var reVers = /Software\\Microsoft\\MSBuild\\ToolsVersions\\([^\r]+)\r\n\s+MSBuildToolsPath\s+REG_SZ\s+([^\r]+)/gi
122+
var cmd = 'reg query "HKLM\\Software\\Microsoft\\MSBuild\\ToolsVersions" /s'
123+
if (process.arch !== 'ia32')
124+
cmd += ' /reg:32'
125+
exec(cmd, function (err, stdout, stderr) {
126+
var reVers = /ToolsVersions\\([^\\]+)$/i
127+
, rePath = /\r\n[ \t]+MSBuildToolsPath[ \t]+REG_SZ[ \t]+([^\r]+)/i
124128
, msbuilds = []
125129
, r
126130
, msbuildPath
127131
if (err) {
128132
return callback(notfoundErr)
129133
}
130-
while (r = reVers.exec(stdout)) {
131-
if (parseFloat(r[1], 10) >= 3.5) {
132-
msbuilds.push({
133-
version: parseFloat(r[1], 10),
134-
path: r[2]
135-
})
134+
stdout.split('\r\n\r\n').forEach(function(l) {
135+
if (!l) return
136+
l = l.trim()
137+
if (r = reVers.exec(l.substring(0, l.indexOf('\r\n')))) {
138+
var ver = parseFloat(r[1], 10)
139+
if (ver >= 3.5) {
140+
if (r = rePath.exec(l)) {
141+
msbuilds.push({
142+
version: ver,
143+
path: r[1]
144+
})
145+
}
146+
}
136147
}
137-
}
148+
})
138149
msbuilds.sort(function (x, y) {
139150
return (x.version < y.version ? -1 : 1)
140151
})

0 commit comments

Comments
 (0)