Reputation: 448
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:
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.
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.
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.
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.
Upvotes: 36
Views: 32505
Reputation: 4976
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.
From the 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.
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
Upvotes: 85