在dotnet发布后运行角度生产版本

时间:2018-03-04 07:44:11

标签: angular asp.net-core visual-studio-code dotnet-cli

我有一个ASP.NET Core 2.0应用程序,Angular 5 SPA托管在同一个文件夹中。

目前要部署到IIS,我执行以下操作:

// 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/

这非常令人沮丧......我怎么能告诉dotnet发布运行ng build -prod?

我尝试将以下内容添加到我的项目csproj文件中:

<Target Name="AngularBuild" AfterTargets="Publish">
  <Exec Command="npm run build --prod" />
</Target>

2 个答案:

答案 0 :(得分:3)

您可以使用任何将逐个调用所有这些命令的任务运行器或自定义脚本。

例如,您可以在package.json中定义自定义npm脚本:

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

然后在需要发布应用时调用npm run apppublish

答案 1 :(得分:2)

在.csproj

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

然后在package.json

"scripts": {
  "build": "npm run build --prod"
}