Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dotnet pack fails when `GeneratePackageOnBuild` is `true`

See original GitHub issue

Using this simple repo: When the <GeneratePackageOnBuild>true</GeneratePackageOnBuild> project attribute is specified and the project has not been built with dotnet build before hand, the build will target netcoreapp2.2 instead of the target framework specified with the <TargetFramework>netstandard2.0</TargetFramework> attribute. When this happens running dotnet pack will build the project into the bin/Debug/netcoreapp2.2 folder instead of bin/Debug/netstandard2.0 and the pack command will fail with the below error:

C:\Program Files\dotnet\sdk\2.2.300\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(199,5): error NU5026: The file 'C:\Repos\dotnetcliissue\bin\Debug\netstandard2.0\testing.dll' to be packed was not found on disk. [C:\Repos\dotnetcliissue\testing.csproj]

Steps to reproduce

Clone Ensure bin/Debug is empty Run dotnet pack from project directory or by providing path the *.csproj

Expected behavior

Should pack project.

Actual behavior

dotnet pack fails with below error:

C:\Program Files\dotnet\sdk\2.2.300\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(199,5): error NU5026: The file 'C:\Repos\dotnetcliissue\bin\Debug\netstandard2.0\testing.dll' to be packed was not found on disk. [C:\Repos\dotnetcliissue\testing.csproj]

Environment data

global.json file (location - C:\Repos):

  "sdk": {
    "version": "2.2.300"

dotnet --info output:

PS C:\Repos\dotnetcliissue> dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   2.2.300
 Commit:    73efd5bd87

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17763
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.2.300\

Host (useful for support):
  Version: 3.0.0-preview5-27626-15
  Commit:  61f30f5a23

.NET Core SDKs installed:
  2.1.505 [C:\Program Files\dotnet\sdk]
  2.1.602 [C:\Program Files\dotnet\sdk]
  2.1.604 [C:\Program Files\dotnet\sdk]
  2.1.700 [C:\Program Files\dotnet\sdk]
  2.1.800-preview-009677 [C:\Program Files\dotnet\sdk]
  2.2.105 [C:\Program Files\dotnet\sdk]
  2.2.202 [C:\Program Files\dotnet\sdk]
  2.2.204 [C:\Program Files\dotnet\sdk]
  2.2.300 [C:\Program Files\dotnet\sdk]
  2.2.400-preview-010195 [C:\Program Files\dotnet\sdk]
  3.0.100-preview5-011568 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0-preview5-19227-01 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0-preview5-27626-15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.0.0-preview5-27626-15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:18
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

nam178commented, Aug 27, 2020

But why this is a no fix?

The setting says “Generate package on build”, it does not say “Don’t build when generating packages”.

caormarccommented, Jan 25, 2022

Until the fix is done, I’m using this workaround in my CI pipelines. I hope it helps!

dotnet pack [<PROJECT>|<SOLUTION>] -p:GeneratePackageOnBuild=false

Read more comments on GitHub >

github_iconTop Results From Across the Web

dotnet pack command - .NET CLI
This can occur when GeneratePackageOnBuild is set, to avoid a cyclic dependency between build and pack targets. The build can also fail if ......
Read more >
Dotnet build and dotnet pack produce different nupkgs
Now, if I just build the project with dotnet pack -c Release it seems as though everything I'd expect to be included, is:...
Read more >
Nuget Pack Failure - The process cannot access the file 'D:\ ...
I finialy found a "reason" to this problem. I can't use dotnet cli on my side because my project is not compatible, but...
Read more >
error NU5026: The file '…' to be packed was not found on disk.
This randomly started happening to me shortly after .NET 5 was released, which I realise may well be just a concidence. It was...
Read more >
Include both Nuget Package References and project ...
Recently I have been trying to generate more Nuget packages for our dotnet core projects, utilizing the dotnet pack command.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found