Azure Pipeline发布:具有特定文件夹或项目的任务DotNetCoreCLI [英] Azure Pipeline Publish: task DotNetCoreCLI with specific folder or project
问题描述
在运行具有以下项目/文件夹结构的Azure生成管道时,我遇到了问题(不需要的行为).
I'm having a problem (unwanted behavior) when running an Azure Build Pipeline with the following project/folder structure.
我的存储库的根文件夹有两个主文件夹:
My repository's root folder has two main folders:
- 前端(ASP.Net Core 2.x& Angular 7项目)
- 后端(ASP.Net Core 2.x)
我正在尝试构建两个单独的Azure管道,一个用于后端,一个用于前端,因此我使用 projects:
参数指定正确的路径.
I'm trying to build two separate Azure Pipelines one for the backend and one for the frontend, so I use the projects:
parameter to specify the correct path.
build
和 test
命令运行良好,仅还原/构建/测试 backend
文件夹,但是 publish
命令在两个文件夹中都运行:backend&前端.
The build
and test
commands are running fine and are only restoring/building/testing the backend
folder, but the publish
command is running for both folders: backend & frontend.
这是我的Yaml文件:
This is my yaml file:
#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
我尝试了不同的文件夹路径,但是它始终运行两个发布命令.
I tried different folder paths but it's always running two publish commands.
如果我在CMD dotnet publish backend
(从仓库的根文件夹中)本地运行,则可以正常运行,但显然不适用于Azure Pipeline.
If I run locally in CMD dotnet publish backend
(from repo's root folder) it works fine but apparently that doesn't work with the Azure Pipeline.
任何想法或修补程序都将不胜感激.
Any ideas or fixes greatly appreciated.
推荐答案
诀窍在于使用publishWebProjects/projects属性.这些实际上是互斥的.如果使用 publishWebProjects
,则将跳过 projects
属性值.
The trick is in using the publishWebProjects/projects properties. Those are actually mutually exclusive. If the publishWebProjects
is used, the projects
property value is skipped.
从文档:
发布Web项目*:如果为true,则任务将尝试查找网络存储库中的项目,然后在它们上运行publish命令.网页通过存在web.config文件或目录中的wwwroot文件夹.
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.
因此,您可以尝试以下代码进行发布:
So you could try the following code for publishing:
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
这篇关于Azure Pipeline发布:具有特定文件夹或项目的任务DotNetCoreCLI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!