dotnet pack fails when `GeneratePackageOnBuild` is `true`
See original GitHub issueUsing 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
Issue Analytics
- State:
- Created 4 years ago
- Reactions:18
- Comments:8 (1 by maintainers)
Top GitHub Comments
But why this is a no fix?
The setting says “Generate package on build”, it does not say “Don’t build when generating packages”.
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