5

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?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Peter Szekeli
  • 2,712
  • 3
  • 30
  • 44
  • You can try to checkout the repo to local machine, if you run the dotnet publish with specific csproj file, will it go to apply for all as well? – wade zhou - MSFT Aug 26 '21 at 03:20
  • @wadezhou-MSFT the command "dotnet publish ..." runs fine, my issue is that the pipeline triggers it for every single project. I'd like it to be executed in the provided folder only. – Peter Szekeli Aug 30 '21 at 06:05
  • What i suggested is to check if you 'dotnet publish' with specific csproj file on local machine, will it apply all projects? If it will, there could be some dependencies between the projects. If it won't, you can migrate the command in pipeline. – wade zhou - MSFT Aug 30 '21 at 07:34

2 Answers2

3

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
Jukka Puranen
  • 8,026
  • 6
  • 27
  • 25
2

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
Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107