1
votes

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).

2
Very strange. According to your description, the issue seems to come from .net core3.1, but I test it with .net core 3.1 on the hosted agent ubuntu-16.04 and ubuntu-18.04, it works fine. Not sure where the argument debug comes from, how about specify the directly argument like: arguments: --configuration Release?Leo Liu-MSFT
I tried with specifying --configuration Release in the arguments, but that didn't help. It still gave the same error with the debug path. I am also on a ubuntu-18.04 hosted agent. And I am using the DotNetCoreCLI pack command, not the NuGetCommand command.Pedro Silva
Found a workaround in the meantime. Replacing the DotNetCoreCLI pack command with the NuGetCommand pack fixes the issue. With that command, I can package the .NET Core 3.1 library into a nuget... Weird that it works with that build task but not the DotNetCoreCLI task.Pedro Silva
Yes, I also test it with DotNetCoreCLI pack command, I haven't heard other voices about this issue either. So, this issue should be more related to the environment, like project file. Anyway, I am glad that you have resolved your question with workaround, would you please convert your comment to the answer before you solution for the issue. This can be beneficial to other community members reading this thread. Thanks.Leo Liu-MSFT
This is a workaround, but not the final answer. The DotNetCoreCLI pack command should work for .NET Core 3.1 projects... shouldn't have to use the NuGetCommand.Pedro Silva

2 Answers

1
votes

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.

1
votes

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, use custom.

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'