I am using a TFS build project to build a Visual Studio 2015 project that contains a gulpfile for compiling SASS among other things. I am trying to understand the sequence of events using MSBuild Tasks and Task Runner bindings. It appears that MSBuild knows enough to detect and run my default gulp task BeforeBuild:
/// <binding BeforeBuild='default' />
var gulp = require('gulp');
var sass = require('gulp-sass');
var importer = require('sass-importer-npm');
gulp.task('sass', function () {
return gulp.src([
'./sass/**/*.scss',
'./node_modules/font-awesome/scss/**/*.scss'
])
.pipe(sass({ importer: importer }).on('error', sass.logError))
.pipe(gulp.dest('./Content/css'));
});
I am to using an MSBuild target to run after the BeforeBuild target so that I can include the generated files in the project for publishing:
<Target Name="CopyGulpFiles" AfterTargets="BeforeBuild">
Here is my MSBuild call in my build .proj file with the relevant info:
<ItemGroup>
<ProjectsToBuild Include="$(MSBuildThisFileDirectory)..\MyProject.sln">
<AdditionalProperties>
VisualStudioVersion=$(VisualStudioVersion);
OutputPath=$(OutputRoot);
WebPublishMethod=FileSystem;
publishUrl=$(StageFolder);
DeployOnBuild=false;
DeployTarget=WebPublish;
PublishProfile=$(MSBuildThisFileFullPath)
</AdditionalProperties>
</ProjectsToBuild>
</ItemGroup>
<MSBuild Projects="@(ProjectsToBuild)" Properties="Configuration=Dev"/>
These two things seem to run in the right order everytime I run them. This raises some questions though:
I ran into the issue where everything worked locally when building with the Task Runner, but Gulp was never called by MSBuild.
I ended up with the following solution, which extends the Compile
task with our custom target GulpBuild
. In this snippet build
is the name of my Gulp task.
<PropertyGroup>
<CompileDependsOn>
$(CompileDependsOn);
GulpBuild;
</CompileDependsOn>
</PropertyGroup>
<Target Name="GulpBuild">
<Exec Command="npm install" />
<Exec Command="gulp build" />
</Target>
Steve Cadwallader's post was very helpful in solving this issue.
BeforeBuild
target should always run before BeforeBuild
in MSBuild. The Task Runner is specific to Visual Studio, so this will only happen when building in Visual Studio.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With