Reputation: 717
I'm trying to build and pack a class library into a NuGet using .NET Core 3.1. It all build fine on my dev machine, but the Azure pipeline build fails during the DotNetCoreCLI pack command. I was able to get the build working on after installing .NET Core 3.1 on the build machine using the UseDotNet. Build and tests run fine, so I believe the 3.1 version is installed correctly.
When I add the pack command, the step always fails. Here is the command I'm using:
- task: DotNetCoreCLI@2
displayName: Package NuGet
inputs:
command: 'pack'
projects: '**/*.csproj'
arguments: '--configuration $(BuildConfiguration)'
outputDir: '$(Build.ArtifactStagingDirectory)/packages'
I get the following error during this step:
/opt/hostedtoolcache/dotnet/sdk/3.1.101/Sdks/NuGet.Build.Tasks.Pack/build/NuGet.Build.Tasks.Pack.targets(198,5): error NU5026: The file '/home/vsts/work/1/s/ClassLib31/bin/Debug/netcoreapp3.1/ClassLib31.dll' to be packed was not found on disk. [/home/vsts/work/1/s/ClassLib31/ClassLib31.csproj]
Notice the path above is looking bin Debug folder, but this is a Release build. All of the tasks are using the same BuildConfiguration variable, but in this task it appears to be looking for the dll in the Debug folder. Any ideas why?
Additional notes: - This build script works fine for .NET Core 3.0 projects. I tried switching the library to target 3.0 and removed the 3.1 installation step. Pack works as expected. - This build script works when I build the Debug version of the library (as you'd expect, since the task is looking in that bin folder).
Upvotes: 1
Views: 6799
Reputation: 1823
DotNetCoreCLI@2 Pack command does not support arguments
argument.
Arguments to the selected command. For example, build configuration, output folder, runtime. The arguments depend on the command selected Note: This input only currently accepts arguments for
build
,publish
,run
,test
,custom
. If you would like to add arguments for a command not listed, usecustom
.
You may use arguments
argument for build
command and configuration
argument for pack
command:
- task: DotNetCoreCLI@2
displayName: Build
inputs:
command: 'build'
arguments: '--configuration Release'
...
- task: DotNetCoreCLI@2
displayName: Pack
inputs:
command: 'pack'
configuration: 'Release'
...
There is another workaround, but note that in this case packagesToPack
argument does not work:
# command: 'pack'
command: custom
custom: pack
arguments: '--configuration Release'
Upvotes: 3
Reputation: 717
After a little more time debugging the build pipeline, I discovered that I had mismatched case the BuildConfiguration variable in a couple of places, which caused this to fail in the pack command. I discovered this while combing through the logs for each step.
It seems that if the case mismatch is in earlier commands (like build and test) they default to the release build. But for the pack command it seems to default to look in the debug bin folder. Once I discovered this and cleaned up the script, it works fine now .NET Core 3.1 builds.
Upvotes: 1