.netazure-devopsnugetpackpackagereference

Dotnet pack with projectstyle PackageReference on Azure Devops fails with "NuGet Error NU5019: File not found"


I'm trying to produce a NuGet package from a C# project on Azure DevOps. I've set up a 'dotnet pack' task in a build pipeline for generating the package. The project is targeting netstandard20. The projectstyle is PackageReference. It has some dependencies, but only ones available on nuget.org.

The build task fails with error NU5019: File not found

Here's the output from the build task:

Build log

NU5019 means that the nuspec file "...contained files that do not exist": https://learn.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu5019

The extracted .nuspec file which is generated by the build task contains this <files> section:

  <files>
    <file src="C:\agent\_work\23\s\GenericDataAccess\bin\Production\netstandard2.0\Sparinvest.GenericDataAccess.dll" target="lib\netstandard2.0\Sparinvest.GenericDataAccess.dll" />
  </files>

It seems to me, the build step builds the .dll and then immediately is unable to find it for packing. However, the .dll is produced.

When I execute the same commandline (seen in the build log) locally on my machine, there's no problem.

I notice, however, that .Net versions are not the same on my machine vs. the build server (see build log): My machine

Can anyone help me to figure out what the problem is with the build step and how I can make it work?

NOTE: I would prefer to use 'dotnet pack' rather than NuGet.exe, because dotnet is able to include dependencies in the pack (NuGet doesn't support PackageReference style).


Solution

  • This appears to be an issue solved with newer Tooling versions (I see your msbuild version is 16.3 - at the time of writing recent SDKs carry 16.9 or a 16.10 preview).

    Use the Use .NET Core task to install a more recent dotnet SDK version either through the pipeline UI or for YAML pipelines use something like:

    - task: UseDotNet@2
      displayName: 'Install .NetCore 5.0.x'
      inputs:
        packageType: 'sdk'
        version: '5.0.x'