dotnet cli publish command vs visual studio publish

时间:2019-04-08 12:52:46

标签: .net-core dotnet-cli

Im setting up a Azure devops build pipeline for a .NET core 2.2 web app that includes Angular and one of the steps it runs is dotnet publish. However, the end result is not what i was expecting compared to when running a publish directly from VS 2017.

As a way to run custom npm commands to target specific environments. So in my csproj file I have this

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

However, the devops build was not running the correct command. After looking at the build log, it was simply running ng build, not including the extra flags to target a specific config.

So then to confirm this, I ran at a command line

dotnet publish -c Test

, and sure enough, the output indicated it ran ng build, without seemingly using what was in the csproj file.

How then can I get my npm command to take the configuration values like those in the csproj file but when dotnet publish runs?

1 个答案:

答案 0 :(得分:1)

建议不要像这样通过MSBuild来获取参数,而是建议将您的npm命令移动到package.json中。

"scripts": {
"buildTest": "npm run build --prod false --configuration=dev",
"buildProd": "npm run build --prod true --configuration=prod"
}

然后使用csproj来运行npm run buildTestnpm run buildProd,依此类推。