How to execute different gulp tasks before/after publish based on environment/run configuration?

I have a small single page asp.net core site that only serves static files from wwwroot. I have several different environments/run configurations for this site. I would like to run different gulp tasks based on which environment I am currently on at build time before publish for each configuration or in some other way prepare my static files based on the release I am on. What are the ways to do this in asp.net core as of now?

The problem is quite similar to How to rewrite a file before publish based on build configuration? but the top voted answer there does not work in my case unless there is a way to run gulp tasks on the server after deploy.

Upvotes: 1

Views: 820

Answers (1)

I solved the problem with manually adding the following to my projects .xproj file within the <Project> tag:

<Target Name="BeforeBuild">
    <Message Text="Running gulp task: $(ConfigurationName)" Importance="high" />
    <Exec Command="cmd.exe /c gulp --color --gulpfile &quot;.\gulpfile.js&quot; $(ConfigurationName)" WorkingDirectory="$(ProjectDir)" />
</Target>

The command will execute gulp with a task named after the current run configuration name (eg Debug or Release) using a gulpfile.js in the project root directory.

In my gulp file I added tasks for each of my run configurations like this (for Realese):

gulp.task('Release', function () {
    // your release gulp steps here, eg. minification and rev-ing
});

Upvotes: 3

Related Questions