Evonet
Evonet

Reputation: 3640

Run angular production release after dotnet publish

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>

Upvotes: 8

Views: 7620

Answers (2)

Capdiem
Capdiem

Reputation: 41

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"
}

Upvotes: 4

Set
Set

Reputation: 49769

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.

Upvotes: 3

Related Questions