Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 553
Evonet Avatar asked Mar 04 '18 07:03

Evonet


People also ask

What does dotnet publish command do?

dotnet publish compiles the application, reads through its dependencies specified in the project file, and publishes the resulting set of files to a directory. The output includes the following assets: Intermediate Language (IL) code in an assembly with a dll extension.


2 Answers

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"
}
like image 163
Capdiem Avatar answered Oct 20 '22 03:10

Capdiem


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.

like image 33
Set Avatar answered Oct 20 '22 05:10

Set