Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Pipeline Publish: task DotNetCoreCLI with specific folder or project

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:

  • frontend (ASP.Net Core 2.x & Angular 7 project)
  • backend (ASP.Net Core 2.x)

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.

like image 446
Federico Rodriguez Avatar asked Nov 16 '18 16:11

Federico Rodriguez


People also ask

What does Dotnetcorecli 2 do?

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.


1 Answers

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
like image 116
Herman Cordes Avatar answered Oct 13 '22 01:10

Herman Cordes