简体   繁体   中英

Nuget package creation - Class library that targets .NET framework 4.6.1 can not target correct framework

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

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:

在此处输入图像描述 (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:

在此处输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM