我有一个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>
答案 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"
}