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>
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.
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"
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With