8

I have an ASP.NET Core 2.0 application with and Angular 5 SPA hosted in the same folder.

Currently to deploy to IIS, I do the following:

// First publish the release configuration
dotnet publish -c release 
// Now delete the wwwroot directory as it is pulished with ng build
rm -r bin/release/netcoreapp2.0/publish/wwwroot
// Build the prod version of the angular app
ng build --prod
// copy the new wwwroot folder into the publish folder
cp -R wwwroot bin/release/netcoreapp2.0/publish/

This is very convulted ... how can I tell dotnet publish to run ng build --prod?

I have tried adding the following into my project csproj file:

<Target Name="AngularBuild" AfterTargets="Publish">
  <Exec Command="npm run build --prod" />
</Target>
Set
  • 47,577
  • 22
  • 132
  • 150
Evonet
  • 3,600
  • 4
  • 37
  • 83

2 Answers2

4

in .csproj

<Target Name="Build Angular" Condition="'$(Configuration)'=='Release'" BeforeTargets="Build">
  <Message Text="* * * * * * Building Angular App * * * * * *" Importance="high"/>
  <Exec Command="npm run build"/>
</Target> 

and then in package.json

"scripts": {
  "build": "npm run build --prod"
}
Capdiem
  • 41
  • 3
3

You may use any task runner or custom script that will call all these commands together one by one.

For example, you may define a custom npm script in package.json:

{
  ...
  "scripts": {
    "apppublish": "dotnet publish -c release && npm run build --prod",
    ...
  }
}

and then just call npm run apppublish when you need to publish app.

Set
  • 47,577
  • 22
  • 132
  • 150
  • This is helpful, and probably what I'll end up doing, however I am still building the angular version twice, once with dotnet publish and again with npm run build – Evonet Mar 04 '18 at 08:16
  • @Evonet why you do not [exclude content](https://stackoverflow.com/questions/42712055/asp-net-core-exclude-or-include-files-on-publish/42713770#42713770) of `wwwroot` from publishing? – Set Mar 04 '18 at 08:19
  • I'll have a look! – Evonet Mar 04 '18 at 08:21