Sdk: dotnet pack fails when `GeneratePackageOnBuild` is `true`

Created on 18 Jun 2019  路  5Comments  路  Source: dotnet/sdk

Using this simple repo: https://github.com/daniefer/dotnetcliissue
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 https://github.com/daniefer/dotnetcliissue
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:
  https://aka.ms/dotnet-download

Most helpful comment

But why this is a no fix?

The setting says "Generate package on build", it does not say "Don't build when generating packages".

All 5 comments

@wli3 can you take a look at this issue?

It is not really related to target framework. It is actually due to the following logic. When GeneratePackageOnBuild=true, it will skip the build step. So there is no built dll to pack.

https://github.com/NuGet/NuGet.Client/blob/ad3e1a24a5fcf3fe5d062c4fef854a97932e11d6/src/NuGet.Core/NuGet.Build.Tasks.Pack/NuGet.Build.Tasks.Pack.targets#L51

@nkolev92 this is issue an I am thinking to no fix. See https://github.com/dotnet/sdk/pull/3473#issuecomment-516169229, it is a set of issue that is very brittle

But why this is a no fix?

The setting says "Generate package on build", it does not say "Don't build when generating packages".

Was this page helpful?
0 / 5 - 0 ratings