我正在使用Gulp使用gulp-msbuild构建我的Web项目。但是,我有多个Web项目,这些项目需要具有不同的构建参数才能发布到正确的文件夹中。
这是我的gulpfile.js的一部分:
gulp.task('publish', function () {
var webProjectsPaths = [
'/Project1/Project1.csproj'
'/Project2/Project2.csproj'
];
return gulp
.src(webProjectsPaths)
.pipe(msbuild({
targets: ['WebPublish'],
toolsVersion: 14.0,
errorOnFail: true,
stdout: true,
properties: {
Configuration: 'Debug',
WebPublishMethod: 'FileSystem',
DeleteExistingFiles: true,
PublishUrl: 'Publish/##csproj file name without the extension##'
},
}));
});
我想在传递给任务.src
之前访问传递给它的每个路径,msbuild
以便进行PublishUrl
动态处理(请参阅参考资料##csproj file name without the extension##
)。
如果将该gulp管道移至某个函数中,则该函数可以确定路径并提前发布url。
// returns one stream that builds one project
function buildWebProject(projectName) {
var path = '/' + projectName + '/' + projectName + '.csproj';
var publishUrl = 'Publish/' + projectName;
return gulp.src(path)
.pipe(msbuild({
targets: ['WebPublish'],
toolsVersion: 14.0,
errorOnFail: true,
stdout: true,
properties: {
Configuration: 'Debug',
WebPublishMethod: 'FileSystem',
DeleteExistingFiles: true,
PublishUrl: publishUrl
}
}));
}
然后在您的“发布” gulp任务中,使用该功能为每个项目创建一个流,并使用诸如merge-stream之类的模块将这些流组合为单个流,然后返回合并的流。
var mergeStream = require('merge-stream');
gulp.task('publish', function () {
var webProjects = [
'Project1',
'Project2'
];
var streams = webProjects.map(buildWebProject);
return mergeStream(streams);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句