NuGet dependencies - getting NU5128 warning when targetFramework is specified

  • Thread starter Thread starter DavidHrbek
  • Start date Start date
D

DavidHrbek

Guest
I have a project targeted to .NET Framework 4. I am using nuget.exe (version 5.6.0.6591) to create the NuGet package. The project itself has no other references than Microsoft.CSharp and System assemblies (none of these have specific version set).

First, I have created a MyProject.nuspec file (by running nuget spec in the MyProject.csproj folder). Then I tried running nuget pack MyProject.csproj and got the NuGet package (the .nupkg archive). But I also got this 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.0 to the nuspec


As per Microsoft's description of NU5128 warning, I have modified my .nuspec file so that now it looks like this (note the <dependencies> tag):

<?xml version="1.0" encoding="utf-8"?>
<package>
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>$author$</authors>
<owners>$author$</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<releaseNotes></releaseNotes>
<copyright>Copyright 2020</copyright>
<tags>my tags here</tags>
<dependencies>
<group targetFramework=".NETFramework4.0" />
</dependencies>
</metadata>
</package>

However, I am still getting the warning. And when I open the .nuspec file within the generated .nupkg archive, there is only empty <dependencies /> tag there.

One workaround I found is to substitute the variables in .nuspec file and call nuget pack MyProject.nuspec instead of nuget pack MyProject.csproj. Then I get this same .nuspec file, including the target framework dependency, within my resulting .nupkg archive. But this deprives me of having nuget automatically filling in version for me.

Either way, when I run nuget pack with -Verbosity detailed, I see the Dependendecies are empty:


Id: MyId
Version: 1.0.0
Authors: Me
Description: My description
Tags: my, tags, here
Dependencies:

It seems that when I call nuget pack on .csproj, it fills in the variables, but it also removes the dependencies, as it considers them empty, yet it gives me the warning afterwards. If I call nuget pack on .nuspec, it packs it as it is, including the dependencies, thus avoiding the warning.

Any ideas how could I resolve the warning while having nuget filling in the variables? And can the fact the target framework is not specified in my package have negative consequences for anyone using the package?

Continue reading...
 
Back
Top