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.
Build, test, package, or publish a dotnet application, or run a custom dotnet command. Build, test, package, or publish a dotnet application, or run a custom dotnet command. For package commands, supports NuGet.org and authenticated feeds like Package Management and MyGet.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With