代码之家  ›  专栏  ›  技术社区  ›  Evonet

在dotnet发布后运行angular production release

  •  8
  • Evonet  · 技术社区  · 8 年前

    我有一个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>
    
    2 回复  |  直到 8 年前
        1
  •  4
  •   Capdiem    8 年前

    在里面项目文件

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

    然后打包。json

    "scripts": {
      "build": "npm run build --prod"
    }
    
        2
  •  3
  •   Set    8 年前

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

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

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

    然后打电话 npm run apppublish 当您需要发布应用程序时。

    推荐文章