0
votes

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?

1
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
@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. - Szeki
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

1 Answers

1
votes

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