17

I created a class library that targets .net framework 4.6.1 (so pretty much a blank canvas, with a single method to return a string, just for testing purposes). I want to make this into a nuget package. I'm following this article https://learn.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package-using-visual-studio-net-framework , but when I get to "nuget pack" I get the following warning:

"WARNING: NU5128: Some target frameworks declared in the dependencies group of the nuspec and the lib/ref folder do not have exact matches in the other location. Consult the list of actions below:
- Add a dependency group for .NETFramework4.6.1 to the nuspec"

I tried adding the dependency group to the .nuspec file:

<?xml version="1.0"?> 
<package>
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <title>$title$</title>
    <authors>Author</authors>
    <owners>$author$</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>H</description>
    <copyright>Copyright 2019</copyright>
    <tags>blah</tags>
    <dependencies>
      <group targetFramework=".NETFramework4.6.1" />
    </dependencies>   
  </metadata> 
</package>

and I also tried:

<?xml version="1.0"?> 
<package>
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <title>$title$</title>
    <authors>Author</authors>
    <owners>$author$</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>H</description>
    <copyright>Copyright 2019</copyright>
    <tags>blah</tags>
    <dependencies>
      <group targetFramework="net461" />
    </dependencies>   
  </metadata> 
</package>

I still get same error.

I tried using older versions of nuget, where the warning message isn't shown, but the same problem persists (If I try to add via the package manager, it says it has no dependencies).

FlashOver
  • 1,855
  • 1
  • 13
  • 24
Billy
  • 357
  • 1
  • 5
  • 14
  • Open the generated package as ZIP and then check the folder structure in it. Edit your question to include that please. – Lex Li Nov 08 '19 at 17:24
  • Will your project have nuget dependencies, and if so, is it necessary for it to use packages.config? If the answer is no or "i don't know", try instead [following the instructions to create a `.NET Standard` package](https://docs.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package-using-visual-studio?tabs=netcore-cli). If you need to target netfx, then right click the project in solution explorer, select edit project file and change the `TargetFramework` element to use `net461` instead of `netstandard2.0`. Pack that (with VS or dotnet.exe) and see if you have the same issue – zivkan Nov 09 '19 at 13:17
  • Hi, any update for this issue? Apart from nuget pack, you could also consider using [`msbuild /t:pack`](https://learn.microsoft.com/en-us/nuget/create-packages/creating-a-package-msbuild#add-the-nugetbuildtaskspack-package) command. I assume you're in a .net framework project with packagereference, then you can check if `msbuild command` can meet your needs. May it makes some help :-) – LoLance Nov 14 '19 at 12:52

1 Answers1

13

WARNING: NU5128: Some target frameworks declared in the dependencies group of the nuspec and the lib/ref folder do not have exact matches in the other location. Consult the list of actions below.

This is an open issue in Github/Nuget, see #8713. I can reproduce same issue in my VS2017 with Nuget V5.3, and this issue goes away if I use Nuget V5.2 or earlier. For this situation, I'm afraid you have to use earlier versions of Nuget.exe until the team releases the fix.

If I try to add via the package manager, it says it has no dependencies

1.If it displays no package dependencies though your package project depends on some nuget packages, please check if you're using packageReference to manage nuget in your current project. For now, nuget pack command doesn't work well for .net framework projects with packageReference or new SDK format projects.

You can check details from Leo's answer to resolve this issue.

2.If the no dependencies you mean is that when one project consumes your package, it doesn't display which framework your project targets like this:

enter image description here (We can see your package depends on Newtonsoft.Json but we can't find which framework it targets(net461).)

For this, we need to use command like nuget pack xx.nuspec to add the dependencies+group into package when packing. Then we can see both targets framework and dependent packages like this:

enter image description here

Hope all above helps and if I misunderstand anything, feel free to correct me :)

LoLance
  • 25,666
  • 1
  • 39
  • 73
  • 2
    I can confirm this is still an issue in Nuget v5.4; and GitHub issue #8713 is still open; and downgrading to v5.2 still seems to be the mandatory fix (which worked for me) :( – Sean Werkema Mar 01 '20 at 01:24
  • Hi there, I also noticed this behavior. And I also tried to use the pack command with the nuspec-file. But if I do so my whole Project-Folder get's packed into the package, including the .cs-Files, bin-Folder, obj-Folder and so on... If I only use the pack command without spec-File it gets packed nicely, but the spec-File is missing the Framework-Group I defined in it. Am I missing something? I've read something about the "convention-based working directory". But I'd like to keep the VS Default Structure. Isn't it possible to use the nuspec-File and pack the package the way like you didn't? – daily Jul 20 '20 at 14:59
  • Still a problem with 5.11. I downgraded to 5.2 and this resolved my problem - cheers! – to6y Oct 07 '21 at 14:08
  • Thank you for this answer. Solved my issue with downgrading to nuget.exe version 5.2 – DhyMik Dec 04 '21 at 08:17