Reputation: 71
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 https://learn.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu5128, 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?
Upvotes: 7
Views: 1901
Reputation: 686
I was having the same issue. The documentation on warning NU5128 (Scenario 1) suggests running nuget's pack target on the project instead of calling nuget pack
. Note that this requires your project to use PackageReference
for its own nuget dependencies.
After installing the NuGet.Build.Tasks.Pack package and building with msbuild -t:pack -p:Authors=JustAGuy
, I get the nuspec dependencies automatically generated as expected.
Upvotes: 0
Reputation: 15
Version 5.2.0 works as well. I was not able to resolve the issue with versions newer than that (up to version 5.8.1).
Upvotes: 0