Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnet pack fails when GeneratePackageOnBuild is true #10335

Open
daniefer opened this issue Jun 18, 2019 · 11 comments
Open

dotnet pack fails when GeneratePackageOnBuild is true #10335

daniefer opened this issue Jun 18, 2019 · 11 comments

Comments

@daniefer
Copy link

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
@livarcocc
Copy link
Contributor

@wli3 can you take a look at this issue?

@wli3
Copy link

wli3 commented Jul 30, 2019

the same issue as #3471

@wli3
Copy link

wli3 commented Jul 30, 2019

More info here #3473 (comment)

@wli3
Copy link

wli3 commented Jul 30, 2019

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 #3473 (comment), it is a set of issue that is very brittle

@wli3 wli3 changed the title dotnet pack fails because command builds project into wrong target directory dotnet pack fails when GeneratePackageOnBuild is true Aug 7, 2019
@msftgits msftgits transferred this issue from dotnet/cli Jan 31, 2020
@msftgits msftgits added this to the Discussion milestone Jan 31, 2020
@nam178
Copy link

nam178 commented 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".

@wli3 wli3 removed their assignment Sep 29, 2021
paterasMSFT added a commit to Azure/azure-sdk-for-net that referenced this issue Oct 27, 2021
Revert "Set RestorePackagePath"

This reverts commit f69ea24ed26d600c35d2df438804a8e7f121b731.

Removed GeneratePackageOnBuild

This resolved a packing issue. See [here](dotnet/sdk#10335) for more information.
@woeterman94
Copy link

any update? 🙃

paterasMSFT added a commit to Azure/azure-sdk-for-net that referenced this issue Nov 1, 2021
Revert "Set RestorePackagePath"

This reverts commit f69ea24ed26d600c35d2df438804a8e7f121b731.

Removed GeneratePackageOnBuild

This resolved a packing issue. See [here](dotnet/sdk#10335) for more information.
paterasMSFT added a commit to Azure/azure-sdk-for-net that referenced this issue Nov 2, 2021
Revert "Set RestorePackagePath"

This reverts commit f69ea24ed26d600c35d2df438804a8e7f121b731.

Removed GeneratePackageOnBuild

This resolved a packing issue. See [here](dotnet/sdk#10335) for more information.
paterasMSFT added a commit to Azure/azure-sdk-for-net that referenced this issue Nov 3, 2021
* Fixed BatchAccountIdentity constructor breaking change.

Changed test location for CloudService test.

Update changelog and version.

Added more legacy constructors.

Fixed constructor and test

Add another 2 argument constructor for BatchAccountIdentity

Mark legacy identity class and related constructor as obsolete

Mark legacy identity class and related constructor as obsolete

Added nuget config to fix package build order issue.

Revert "Added nuget config to fix package build order issue."

This reverts commit b59ade3.

Updated batch version

Revert "Updated batch version"

This reverts commit 86a050d.

Fixed changelog date

Fixed changelog

* Updated session recordings

Session records

Updated session recordings.

Updated location filter value to fix scenario test.

* Updated batch version

Updated package version

Updated version

Fixed versioning

Fixed version

Reverted to v4.2, will address in pending DataPlane update.

* Removed GeneratePackageOnBuild

Revert "Set RestorePackagePath"

This reverts commit f69ea24ed26d600c35d2df438804a8e7f121b731.

Removed GeneratePackageOnBuild

This resolved a packing issue. See [here](dotnet/sdk#10335) for more information.
@SuperJMN
Copy link

SuperJMN commented Nov 9, 2021

I think I've hit this problem, too, in Azure Pipelines and locally.

pgodwin added a commit to pgodwin/PictSharp that referenced this issue Jan 5, 2022
pgodwin added a commit to pgodwin/PictSharp that referenced this issue Jan 5, 2022
Fix nuget deployment
Add .NET 4.7.2 example
Fix package output path to reduce filesize.
Use semantic-version
Get rid of .NET 3.1 on build (for now?)
Remove `GeneratePackageOnBuild`: dotnet/sdk#10335
Move test to it's own step
Use GitHubActionsTestLogger for tests
Force win target for PictSharp.drawing

Try combining actions

Add .net core needed for .net standard?

Fix project path

Fix msbuild

Another fix of actions

Remove msbuild path from windows build

Add BuildNetCore option to prevent net472 tests running

Fix readme and try fix dotnet test under linux

Add Manual Build process

Fix all warnings, and add XML comments

MsBuild package fixes

Fix up license to MIT
@caormarc
Copy link

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

@davidhenley
Copy link

davidhenley commented Nov 13, 2023

Is there an update on this? It's been almost 2 years.

@DarkDibblez
Copy link

DarkDibblez commented Nov 16, 2023

Causes problems for me as well. I have a web API app and an nswag generated client project. I publish the webapp and run pack on the client project, but because GeneratePackageOnBuild = true it fails. Removing GeneratePackageOnBuild=true from my csproj allows the step to complete successfully.

GeneratePackageOnBuild implies a package is made when the project is built, it does not imply the project has been built when the pack step is run.

@sjanisz
Copy link

sjanisz commented Nov 24, 2023

I have encountered this suddenly in my pipeline too, and it was unexpected as it worked previously with GeneratePackageOnBuild set to true in project settings - now I had to set it to false. Last time it worked was Oct 10, next time I have tried to run pipeline was today (Nov 24) - very upsetting. My pipeline consists of 2 separate stages and jobs, first stage + job is Pack:

stages:
- stage: Pack
  variables:
    - name: Projects
      value: |
        $(LibraryPresentationProject)
  jobs:
  - job: Pack
    steps:
    - template: Templates/RestoreAndBuild.yml
      parameters:
        vstsFeed: $(NugetVstsFeed)
        projects: $(Projects)
    - task: DotNetCoreCLI@2
      displayName: 'NuGet pack'
      inputs:
        command: pack
        packagesToPack: $(Projects)
        packDestination: '$(Build.ArtifactStagingDirectory)'
        versionEnvVar: 'VersionPresentation'
        versioningScheme: 'byEnvVar'
    - publish: $(Build.ArtifactStagingDirectory)
      artifact: PackArtifacts

second is publish:

stages:
- stage: Publish
  jobs:
  - job: Publish
    steps:
    - download: current
      artifact: PackArtifacts
    - task: NuGetAuthenticate@0
      displayName: 'NuGet Authenticate'
    - task: NuGetCommand@2
      displayName: 'NuGet push'
      inputs:
        command: push
        packagesToPush: '$(Pipeline.Workspace)/PackArtifacts/*.nupkg'
        publishVstsFeed: '$(ProjectName)/$(FeedName)'
        allowPackageConflicts: true

lastly i wrap both stages in following yaml:

pool:
  vmImage: windows-latest

trigger: none

variables:
  - template: variables.yml

stages:
  - template: pack.yml
  - template: publish.yml

for completeness Templates/RestoreAndBuild.yml content below:

parameters:
- name: vstsFeed
  type: string
- name: projects
  type: string

steps:
- task: DotNetCoreCLI@2
  displayName: 'Restore'
  inputs:
    command: restore
    feedsToUse: 'select'
    vstsFeed: ${{ parameters.vstsFeed }}
    projects: ${{ parameters.projects }}
- task: DotNetCoreCLI@2
  displayName: 'Build'
  inputs:
    command: 'build'
    projects: ${{ parameters.projects }}
    arguments: '--configuration Debug'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests