Azure Pipeline 发布:具有特定文件夹或项目的任务 DotNetCoreCLI

Azure Pipeline Publish: task DotNetCoreCLI with specific folder or project

我在 运行 使用以下 project/folder 结构构建 Azure Build Pipeline 时遇到问题(意外行为)。

我的存储库的根文件夹有两个主要文件夹:

我正在尝试构建两个单独的 Azure 管道,一个用于后端,一个用于前端,因此我使用 projects: 参数指定正确的路径。

buildtest 命令 运行 没问题,只是 restoring/building/testing backend 文件夹,但是 publish 命令运行两个文件夹都在:后端和前端。

这是我的 yaml 文件:

 #build backend project
 task: DotNetCoreCLI@2
   displayName: dotnet build --configuration $(buildConfiguration)
   name: BuildBackendProject
   inputs:
     command: build
     projects: '**/backend/**/*.csproj'
     arguments: '--configuration $(buildConfiguration)'

 ... #run some tests

 #publish backend project
 task: DotNetCoreCLI@2
   displayName: dotnet publish backend --configuration $(buildConfiguration)
   name: PublishBackendProject
   inputs:
     command: publish
     projects: '**/backend/**/*.csproj'
     publishWebProjects: True
     arguments: '--configuration $(BuildConfiguration) --output 
     $(Build.ArtifactStagingDirectory)/backend'
     zipAfterPublish: True

我尝试了不同的文件夹路径,但它总是 运行宁两个发布命令。

如果我 运行 在本地 CMD dotnet publish backend(从 repo 的根文件夹)它工作正常但显然不适用于 Azure Pipeline。

非常感谢任何想法或修复。

诀窍在于使用 publishWebProjects/projects 属性。这些实际上是相互排斥的。如果使用 publishWebProjects,则跳过 projects 属性 值。

来自documentation

Publish Web Projects*: If true, the task will try to find the web projects in the repository and run the publish command on them. Web projects are identified by presence of either a web.config file or wwwroot folder in the directory.

所以您可以尝试使用以下代码进行发布:

task: DotNetCoreCLI@2
  displayName: dotnet publish backend --configuration $(buildConfiguration)
  name: PublishBackendProject
  inputs:
    command: publish
    projects: '**/backend/**/*.csproj'
    publishWebProjects: false
    arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)/backend'
    zipAfterPublish: true