-
Notifications
You must be signed in to change notification settings - Fork 255
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
nuget pack is ignoring dependencies when using PackageReference instead of packages.config #5979
Comments
nuget.exe pack currently doesn't support package reference based projects. To package your C# Class Library which manages your dependencies via PackageReference in the csproj itself, please add a reference to NuGet.Build.Tasks.Pack ( https://www.nuget.org/packages/NuGet.Build.Tasks.Pack/) and run msbuild /t:pack from the command line. we are still actively working on improving this scenario, please let us know whatever you find missing. |
I will try that. Thanks, @rohit21agrawal. |
@rohit21agrawal , my project is .NET 4.5. |
@rafaelromao oh sorry, i forgot to specify - you will have to add a property |
if it also complains about Authors, then set a property for |
I could make a PoC work by running: |
Awesome! Please note that this scenario is still a work in progress (original msbuild /t:pack was designed to work with NETCore SDK based projects identified by having |
Sure. I will comment here if I have any issues implementing that. Thanks |
we already have a tracking issue for this effort : #5918 . I am going to close this issue and would appreciate if you can comment on the tracking issue. |
We have added a reference to NuGet.Build.Tasks.Pack in a .NET 4.6.1 project. If we configure the TargetFramework property in csproj an error occurs:
But if we set the TargetFramework property through the command line works fine: Thanks in advance |
Due to bug NuGet/Home#5979, when creating a NuGet packages, the dependencies are not populated in the generated nupkg file based on PackageReference in csproj (but are if packages.config is present). Since this only impacts projects for redistribution via NuGet, those projects have their PackageReference changes reverted to packages.config
Due to bug NuGet/Home#5979, when creating a NuGet packages, the dependencies are not populated in the generated nupkg file based on PackageReference in csproj (but are if packages.config is present). Since this only impacts projects for redistribution via NuGet, those projects have their PackageReference changes reverted to packages.config
Why was this issue closed??? |
We have converted our projects under .NET Framework 4.7 from packages.config to packagereferences, but when we published nuget package for one of projects it lacks nuget dependencies. If there is no solution, is there only 1 way to get back to packages config by deleting all package references and adding them via Nuget package manager? Thanks, |
Been struggling with this one for a while... the only solution I've found which works is to manually add the dependencies into the .nuspec file and use nuget.exe pack. Using msbuild with NuGet.Build.Tasks.Pack does include dependencies but ignore info in the AssemblyInfo.cs so I end up with defaults e.g version 1.0.0. You can use msbuild to generate the package and copy/paste the dependencies into the .nuspec file but this is still a pain. |
@SimonSDA with the NuGet.Build.Tasks.Pack package, all the attributes in AssemblyInfo.cs can be mapped to appropriate properties in the csproj file which the pack task will pick up. Would that solve the issue for you? https://docs.microsoft.com/en-us/nuget/reference/msbuild-targets#pack-target |
@marvel16 does the following not work for you: To package your C# Class Library which manages your dependencies via PackageReference in the csproj itself, please add a reference to NuGet.Build.Tasks.Pack ( https://www.nuget.org/packages/NuGet.Build.Tasks.Pack/) and run msbuild /t:pack from the command line. |
@rohit21agrawal I've been trying to avoid editing the csproj files as we have over 350 projects :(. I ended up ditching nuget.build.tasks.pack and writing a utility to scan the csproj file and generate the dependencies group, then paste it into the nuspec file. Any internal solution project references I add into the files section which also seems to work. It is a pain that it is still a manual process. |
@rohit21agrawal With packages.config and nuget pack I was able to achieve this by passing the -IncludeReferencedProjects argument. All dependencies were correctly built. Any advice? |
@Rzpeg Can you try the following:
If the version listed in 2) above is 1.5.0 instead of 2.0.0, it's because msbuild /t:pack is also causing a rebuild/restore and passing in 2.0.0 as a version for LibB as well. You can avoid this by passing /p:NoBuild=true when packing. |
@rohit21agrawal did you fix the issue where nuget.exe pack supports packagerefence missing dependencies? |
How is this fixed? I still have the same problem with a 4.6.1 library. Nuget doesn't add the referenced packages as dependencies to the resulting nuspec /nupkg. |
same problem here |
But this is NOT a dupe. Those are different problems. This needs to be re-opened as I am having the same problem. I had to switch back to packages.config to solve mine. |
Not only does this problem still exist in NuGet version 4.9.3 despite closing the issue, the recommended solution of using the NuGet.Build.Tasks.Pack package and MSBuild does not work; the "pack" target is not made available by the addition of this package. |
All my projects referencing NuGet.Build.Tasks.Pack and building with |
@rohit21agrawal I don't get why the issue has been closed. This still doesn't work. With NuGet 5. Even with NuGet.Build.Tasks.Pack. And it is very easy to reproduce: Running:
Results in a SomeLib.EntityFramework.nupkg package, which references v. 2.0.0 of SomeLib.Core, not v. 1.5.0 specified in AssemblyInfo. Instead of fixing nuget pack you guys keep closing every ticket about the topic. By the way, NuGet task pack on Azure Pipelines has the same issues. It doesn't work. Basically, we are forced to use this ugly workaround to pack nugets on Azure Pipelines
|
The steps you are describing are not equivalent. Please create an issue and provide a repro zip of your scenario. (all the steps you are taking) and we can conclusively tell you the expectation. |
It is been two years and the issue still exists. damn. come on microsoft you can do better. are you expecting every one to migrate to .Net Core? |
@rbmanian75 To be fair, the answer to that question is clearly "yes", hence the .NET 5 announcement. |
I agree that this should NOT be closed. None of the alternatives work completely and it seems MS is closing every variant of this problem report that they can. I logged an issue in the Dev Community for azure devops since this was evident in that process. They closed that board item but one of their devs agreed this was a bug and logged it here: microsoft/azure-pipelines-tasks#10301 Hopefully, that one won't get closed until they ACTUALLY solve the problem. We need to keep them accountable. This problem has gone on way too long. |
If you ask me, this is more of a convergence to bring core back to .NET than it is .NET to core. It is all going to be one big happy family now. And hopefully, this problem gets solved before then. |
to solve this problem I'm using a post built event and a PowerShell script (NuGetPackDependencies.ps1) and this solved the problem for me:
|
@patrickkrootjes this wont work for packagereference which have dependencies installed from nuget. |
@rbmanian75 I'm not sure what you mean by "this wont work for packagereference which have dependencies installed from nuget.". I'm using PackageReference for my projects. The way I use it, is that the PowerShell script NuGetPackDependencies.ps1 looks for dependencies inside .csproj and adds those dependencies to .nuspec file. The nuget pack command then produces a NuGet package with the wanted dependencies. This basically solves the problem descibed in this issue. The only problem of this approach is that I have to add the PowerShell script to every project that create a nuget package, but this was manageable. Since it was already clear Microsoft was not going to solve this issue and package config was also no longer maintainable, this was the best approach for me. |
@patrickkrootjes Does this work with nested dependencies? |
@patrickkrootjes Sorry i have overlooked your solution without looking into what you done in powershell. Your solution for adding the dependencies using powershell script works great. But i was facing a small issue when i try to execute the powershell script. I was getting the error Method invocation failed because [System.Xml.XPathNodeList] does not contain a method named 'AppendChild'.
But changing the line 87 to $metaDataElement = $xmlNuspec.package.metadata made it work. Thank You Very Much. |
@edufur i hope it will work for nested dependencies also. Because nusepc contains the dependencies the dependencies will also have dependencies specified in nuspec file and so on. So all dependencies will be installed. |
This needs to be reopened as the issue still persists. |
It's duped to #4491 |
any hope this will ever be fixed? sigh... |
@GiampaoloGabba - Is there a reason why you can't use dotnet.exe pack as per #4491? cc: @JonDouglas |
Is there a reason they choose not to solve the issue?
…-Eric
On Mon, Oct 26, 2020, 6:23 PM Arturo Ortiz ***@***.***> wrote:
@GiampaoloGabba <https://github.com/GiampaoloGabba> - Is there a reason
why you can't use dotnet.exe pack?
cc: @JonDouglas <https://github.com/JonDouglas>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5979 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEUXN5KY4EHTUS4EZA2MM33SMYOH7ANCNFSM4D5NES2A>
.
|
This needs to be re-opened. 3 years have gone by and this is still a problem. dotnet pack is not a useful option unless they library is dotnetcore... which in my case, it is not. |
I'm guessing the intended solution is for people to get off legacy .NET Framework projects and onto .NET 5, 6, and up from there. It's clear that .NET Framework is a dead end at this point. |
NuGet/Home#5979, but switching to `dotnet pack' works?
Just converted Net framework 472 projecst from packages.config to PackageReference in prep for trying to move to NetCore (we cant ATM due to a particular dependency) and its amazing how an issue from 6 years ago is still an issue. Good job Nuget team. Thanks for fking us over. In the meantime this stackoverflow is a decent workaround: It involves a powershell script that reads your CSPROJ/VBPROJ file for the PackageReference nodes and writes them into the nuspec file. Amazing how the Nuget team cant figure out how to do this. I have defended the Nuget problem for years... its complicated to maintain NetFramework NetCore, dependencies of libraries over time, the Fusion runtime's idiotic assembly version binding scheme being exact-match (that needs to be changed to SemVer) and etc but y'all honestly have hit my last nerve with this extremely common scenario. |
NuGet dev edit: Duplicate of #4491
Details about Problem
NuGet product used: nuget.exe
NuGet version: 4.3.0.4406
.NET Framework v4.5 (Full Framewok project, not a dotnet core project)
VS version: 15.3.3
Worked before, when using packages.config instead of PackageReference.
Detailed repro steps
Configure Visual Studio 2017 to use PackageReference instead of packages.config.
Create a new C# Class Library (.NET Framework) targeting .NET Framework 4.5.
Reference some package, like Newtonsoft.json, for example.
Not that no packages.config file will be created and the referenced package will be included in the csproj file.
Create a valid nuspec file without specifying any dependencies (they should be inferred and included automatically)
Run
nuget pack
and check the .nuspec file included in the generated .nupkg file. If should list the dependency packages, in this case Newtonsoft.json, in the dependencies tag, but no dependencies is listed....
Sample Project
https://github.com/rafaelromao/nuget_pack_with_PackageReference
In the sample projects, ClassLibrary1 was created with Visual Studio configured to use PackageReference instead of packages.config. You can see in the .nupack generated by running
nuget pack .\ClassLibrary1.csproj
that the .nuspec file in it does not include any dependencies, while in the ClassLibrary2 project, created using packages.config, the dependencies are included.The text was updated successfully, but these errors were encountered: