Executing Gulp task(s) only when publishing ASP.NET 5 web application
Asked Answered
P

2

10

What would be the best way to execute Gulp tasks only when publishing an ASP.NET 5 web application? Do I need to add a custom build event that executes a Gulp command?

cmd.exe /c gulp -b "C:\Projects\ProjectName\Source\ProjectName.Web" --gulpfile "C:\Projects\ProjectName\Source\ProjectName.Web\Gulpfile.js" publish

Or, preferably, is there a way to bind a Gulp task to the BeforePublish target via the Task Runner Explorer?

Any suggestions would be very appreciated.

Punctual answered 7/8, 2015 at 17:34 Comment(0)
D
4

UPDATE 2 .NET Core CLI doesn't support "prepack" any more. A "postcompile" script may work better.

https://learn.microsoft.com/en-us/dotnet/articles/core/tools/project-json#scripts

Original Answer

Add it to your "scripts" section of project.json

project.json: Scripts documentation

{
...
  "scripts": {
    "prepack": "gulp publish",
  }
...
}
Diploblastic answered 11/8, 2015 at 23:47 Comment(3)
If I wanted it to run before a publish, would I hook into the prepack action?Punctual
Actually, the "prebuild" target may be better if you are using VS tooling to publish.Diploblastic
if you want to run before publish then I think prepublish is the action to use...Click
Y
7

Create the target in your publish profile file (the *.pubxml file still exists in asp.net 5 projects). The pubxml file is a build file and it is added to your proj build file. This way it would only be ran when you publish using that specific profile.
I would use BeforeBuild target to be more generic (all the packages restore, all the injection of js/css in views etc I would do them before the build would start) and add there the gulp command:

<Target Name="BeforeBuild">
   <Exec Command="call gulp" WorkingDirectory="$(ProjectDir)" />
</Target>

This would work no matter if you publish from Visual Studio or with MSBuild from your build machine.

Yokoyama answered 7/8, 2015 at 19:35 Comment(0)
D
4

UPDATE 2 .NET Core CLI doesn't support "prepack" any more. A "postcompile" script may work better.

https://learn.microsoft.com/en-us/dotnet/articles/core/tools/project-json#scripts

Original Answer

Add it to your "scripts" section of project.json

project.json: Scripts documentation

{
...
  "scripts": {
    "prepack": "gulp publish",
  }
...
}
Diploblastic answered 11/8, 2015 at 23:47 Comment(3)
If I wanted it to run before a publish, would I hook into the prepack action?Punctual
Actually, the "prebuild" target may be better if you are using VS tooling to publish.Diploblastic
if you want to run before publish then I think prepublish is the action to use...Click

© 2022 - 2024 — McMap. All rights reserved.