TL;DR
I'm building a nuget package with Azure Devops pipelines, and the DotNetCoreCLI@2 / pack
command is looking for the built assemblies and other files of dependent projects in the wrong folder because the name of the solution configuration the yaml uses is different from the name of the build configuration of the dependent projects the solution configuration uses.
In detail:
The project dependencies in the solution: Main --> DepA --> DepB.
The nuget package is built from Main.
The yaml uses a solution configuration called ReleaseMain
, which ...
- builds only the above projects
- uses the
Release
build configuration of each project. I can't see any point in creating a separate build configuration calledReleaseMain
in each project ifRelease
can be referred to byReleaseMain
.
The relevant parts of the yaml:
variables: buildConfiguration: 'ReleaseMain'steps:- task: NuGetToolInstaller@1- task: DotNetCoreCLI@2 inputs: command: 'restore' projects: '**/Main.csproj' feedsToUse: 'select' vstsFeed: '<nuget feed ID>'# I don't use a DotnetCoreCLI@2 / Build task because the pack command also builds everything it needs. This works with other pipelines.- task: DotNetCoreCLI@2 inputs: command: 'pack' packagesToPack: '**/Main.csproj' versioningScheme: 'off'
The pack
task fails while building the DepB
project because it is looking for obj\ReleaseMain\netstandard2.0\
.NETStandard,Version=v2.0.AssemblyAttributes.cs but doesn't find it, since it is in the obj\Release\netstandard2.0\
folder. Then the log contains the same error for the DepA
project, and the task fails.
So the problem is that the pack
command is looking for release files in a subfolder named after the solution configuration instead of the build configuration of the projects.
In cases when the project from which the nuget package is built has no project dependencies, I can make the pipeline work by specifying the project build configuration name in the files/file
XML elements of the nuspec file, see below.
<files><!-- instead of this --><file src="bin\$configuration$\netcoreapp3.1\Main.dll" target="lib\.NETCoreApp3.1" /><!-- I hardcode this --><file src="bin\release\netcoreapp3.1\Main.dll" target="lib\.NETCoreApp3.1" /></files>
But the build task is stuck before this step in the above scenario, so I only mention this as a side note.
There must be a solution for this because it seems a pretty frequent situation to me but I can't find it. I know I could create a project build configuration called ReleaseMain
for each project but it seems unnecessary. Or is the way the nuget pack
command works incompatible with this setup?