-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulp-msbuild.js
56 lines (43 loc) · 1.25 KB
/
gulp-msbuild.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var exec = require('child_process').exec
, Winreg = require('winreg')
, gutil = require('gulp-util')
, map = require('map-stream');
module.exports = function(options){
if(!options) {
options = {};
}
return map(function (file, cb) {
// see: https://coderwall.com/p/0eds7q
function isOSWin64() {
return process.arch === 'x64' || process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432');
}
var regKey = new Winreg({
hive: Winreg.HKLM,
key : "\\SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\4.0"
});
var pathValueName = isOSWin64() ? "MsBuildToolsPath" : "MsBuildToolsPath32";
regKey.get(pathValueName, function(err, item) {
if(err){
cb(err);
}
else {
options.cwd = process.cwd();
options.projectFile = file.path;
options.msbuild = item.value + 'MSBuild.exe';
var command = '<%= options.msbuild %> <%= options.args %> <%= file.path %>';
var cmd = gutil.template(command, {file:file, options : options});
gutil.log('MSBuild Command: ' + cmd);
exec(cmd, function(error, stdout, stderr){
if(stderr) {
gutil.log(stderr);
}
if(stdout){
stdout = stdout.trim(); // Trim trailing cr-lf
gutil.log(stdout);
}
cb(error, file);
});
}
});
});
}