10
votes

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://docs.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).

1
Open the generated package as ZIP and then check the folder structure in it. Edit your question to include that please.Lex Li
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. 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 issuezivkan
Hi, any update for this issue? Apart from nuget pack, you could also consider using msbuild /t:pack 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

1 Answers

9
votes

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 :)