3 msbuild powershell node.js gulp visual-studio-2015
我正在使用gulp来构建和部署我们的应用程序.
var msbuild = require('gulp-msbuild');
gulp.task('build', ['clean'], function () {
return gulp.src('../../*.sln')
.pipe(msbuild({
toolsVersion: 14.0,
targets: ['Rebuild'],
errorOnFail: true,
properties: {
DeployOnBuild: true,
DeployTarget: 'Package',
PublishProfile: 'Development'
},
maxBuffer: 2048 * 1024,
stderr: true,
stdout: true,
fileLoggerParameters: 'LogFile=Build.log;Append;Verbosity=detailed',
}));
});
Run Code Online (Sandbox Code Playgroud)
但是在构建之后我必须调用PowerShell脚本文件"publish.ps1",如何在gulp中调用它?
Bar*_*000 10
我没有测试过这个,但是如果你把它们结合起来就会看起来像这样.只需运行默认任务,该任务使用run-sequence来管理依赖顺序.
var gulp = require('gulp'),
runSequence = require('run-sequence'),
msbuild = require('gulp-msbuild'),
spawn = require("child_process").spawn,
child;
gulp.task('default', function(){
runSequence('clean', 'build', 'powershell');
});
gulp.task('build', ['clean'], function () {
return gulp.src('../../*.sln')
.pipe(msbuild({
toolsVersion: 14.0,
targets: ['Rebuild'],
errorOnFail: true,
properties: {
DeployOnBuild: true,
DeployTarget: 'Package',
PublishProfile: 'Development'
},
maxBuffer: 2048 * 1024,
stderr: true,
stdout: true,
fileLoggerParameters: 'LogFile=Build.log;Append;Verbosity=detailed',
}));
});
gulp.task('powershell', function(callback){
child = spawn("powershell.exe",["c:\\temp\\helloworld.ps1"]);
child.stdout.on("data",function(data){
console.log("Powershell Data: " + data);
});
child.stderr.on("data",function(data){
console.log("Powershell Errors: " + data);
});
child.on("exit",function(){
console.log("Powershell Script finished");
});
child.stdin.end(); //end input
callback();
});
Run Code Online (Sandbox Code Playgroud)
编辑
使用参数调用powershell文件
var exec = require("child_process").exec;
gulp.task("powershell", function(callback) {
exec(
"Powershell.exe -executionpolicy remotesigned -File file.ps1",
function(err, stdout, stderr) {
console.log(stdout);
callback(err);
}
);
});
Run Code Online (Sandbox Code Playgroud)
Powershell file.ps1位于解决方案的根目录中
Write-Host 'hello'
编辑2
好的,再试一次.你能把params/arguments放在file.ps1中吗?
function Write-Stuff($arg1, $arg2){
Write-Output $arg1;
Write-Output $arg2;
}
Write-Stuff -arg1 "hello" -arg2 "See Ya"
Run Code Online (Sandbox Code Playgroud)
编辑3
从gulp任务中传递参数::
gulp.task('powershell', function (callback) {
exec("Powershell.exe -executionpolicy remotesigned . .\\file.ps1; Write-Stuff -arg1 'My first param' -arg2 'second one here'" , function(err, stdout, stderr){
console.log(stdout);
callback(err)
});
});
Run Code Online (Sandbox Code Playgroud)
更新要删除的file.ps1
function Write-Stuff([string]$arg1, [string]$arg2){
Write-Output $arg1;
Write-Output $arg2;
}
Run Code Online (Sandbox Code Playgroud)