首页 > 解决方案 > 使用 .NET Core 和 Angular 构建管道,但在发布任务期间发生 npm 构建?

问题描述

在解决方案中有一个 .NET Core 2.2 应用程序,并且一直在使用发布配置文件发布到开发服务器。现在,我设置了一个 Devops 构建管道以使用本地自托管代理进行发布。大部分工作,但我看不到正确的 npm 构建配置。

当我在本地使用我的发布配置文件时,我使用 csproj 文件中的设置来控制用于 npm 构建的选项。

例如。

  <Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
    <!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
    <!-- Use conditional builds based on build target setting eg.  debug, dev, prod etc -->
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm run build " Condition=" '$(Configuration)' == 'Debug' " />
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm run build --prod false --configuration=dev" Condition=" '$(Configuration)' == 'Test' " />
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm run build --prod true --configuration=prod" Condition=" '$(Configuration)' == 'Release' " />
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm run build:ssr --configuration=prod" Condition=" '$(BuildServerSideRenderer)' == 'true' And  '$(Configuration)' == 'Release' " />

但是,我的构建管道中的 npm build 直到发布步骤才运行。然后它是默认的“ng build”,没有设置使用正确的角度环境值。

在 npm build 任务中,我将其用于自定义命令

构建 --prod 错误 --configuration=dev

但它似乎没有在构建过程中运行。

如何让正确的 npm 构建设置运行?

我的构建管道看起来像这样 在此处输入图像描述

标签: azure-devops

解决方案


a)我有同样的问题,我通过在脚本中添加一个新命令来更新 package.json 文件解决了这个问题(见附图)

"build-staging": "ng build --configuration=staging"

包.json

b) 我还更新了构建定义 npm build

c)我删除了publishrunwebpack 节点下 .csproj 文件 中的 exec 行e .csproj 文件

这导致根据环境运行正确的 nb build 命令。


推荐阅读