Working directory parameter of DotNetCoreCL Publish step

Viewed 691

I have a repository with many solutions in it. I'd like to set up a build pipeline in Azure DevOps and build specific solution. I only need the "standard" steps as "restore packages, build, run unit tests, publish". However, the "publish" step gives me a headache.

The folder hierarchy for the repository looks like this:

src
    - Solution1
        - Project1
        - Project2
        - Project3
    - Solution2
        - Project4
        - Project5
    ...

My goal would be to publish only the projects of e.g. Solution2 - so Project4 and Project5. Setting the value of workingDirectory to "src/Solution2" or "$(System.DefaultWorkingDirectory)/src/Solution2" don't work as I expected.

Here's the definition of the build step.

- task: DotNetCoreCLI@2
  displayName: Publish
  inputs:
    command: publish
    arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
    workingDirectory: src/Solution2

In the logs, I see

"C:\Program Files\dotnet\dotnet.exe" publish [path_to_agent]_work\1\s\src\Solution1\Project1\Project1.csproj --configuration Release --output [path_to_agent]_work\1\a\Project1

and similar entries for every single project in the repository.

As a workaround I tried using the "custom" command, but it didn't work out either.

- task: DotNetCoreCLI@2
  displayName: 'Publish'
  inputs:
    command: custom
    arguments: 'src/Solution2 --configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory) '
    custom: publish

This produces a log entry as

"C:\Program Files\dotnet\dotnet.exe" publish [path_to_agent]_work\1\s\src\Solution1\Project1\Project1.csproj src/Solution2 --configuration Release --output [path_to_agent]_work\1\a\Project1

and eventually the pipeline fails as Only one project can be specified.

Any ideas what I'm doing wrong?

2 Answers

You can try to use projects settings with globbing to get all csproj's:

- task: DotNetCoreCLI@2
  displayName: 'dotnet publish'
  inputs:
    command: 'publish'
    publishWebProjects: false
    projects: 'src/Solution2/**/*.csproj'
    arguments: '-o $(Build.ArtifactStagingDirectory)/Output'
    zipAfterPublish: true
    modifyOutputPath: true

I had the same problem. After a lot of trials and errors I came to the conclusion that the workingdirectory parameter is just ignored as explained here.

Also I noticed globbing (**/*) does not work if you use quotes. Also publishWebProjects has to be set to false otherwise it will start searching for other projects from the default working folder.

So this worked for me:

- task: DotNetCoreCLI@2
inputs:
command: 'publish'
publishWebProjects: false
configuration: $(buildConfiguration)
projects: |
  $(System.DefaultWorkingDirectory)/pathToProjectA/projectA.csproj
  $(System.DefaultWorkingDirectory)/pathToProjectB/*.csproj
Related