【问题标题】:Run angular production release after dotnet publish在 dotnet publish 之后运行 Angular 生产版本
【发布时间】:2018-03-04 07:44:11
【问题描述】:

我有一个 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 publish 运行 ng build --prod?

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

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

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      您可以使用任何任务运行程序或自定义脚本来一一调用所有这些命令。

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

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

      然后当您需要发布应用时,只需致电npm run apppublish

      【讨论】:

      • 这很有帮助,可能是我最终会做的,但是我仍在构建 angular 版本两次,一次使用 dotnet publish,另一次使用 npm run build
      • @Evonet 你为什么不把exclude contentwwwroot 从发布?
      • 我去看看!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-18
      • 2022-01-25
      • 1970-01-01
      • 2019-12-13
      • 2019-06-14
      • 1970-01-01
      • 2017-10-22
      相关资源
      最近更新 更多