NuGet issues a warning NU5128 when csproj is specified as a target and nuspec with the same file name exists in the same directory as csproj file, and has the dependency group specified.
NuGet product used (NuGet.exe | VS UI | Package Manager Console | dotnet.exe): NuGet.exe
NuGet version (x.x.x.xxx): 5.3.0.6260
dotnet.exe --version (if appropriate): 3.0.100
VS version (if appropriate): Visual Studio 2019 Professional
OS version (i.e. win10 v1607 (14393.321)): win10 (17134)
Worked before? If so, with which NuGet version: 5.2
test-project
in the same folder and
test-project.csproj`test-project.nuspec
created in the previous step and add the following dependency group under the metadata
node<dependencies>
<group targetFramework=".NETFramework4.5">
<dependency id="<imported library>" version="<library version>" />
</group>
</dependencies>
NuGet.exe pack .\test-project.csproj
Observe the NU5128 warning.
NuGet Version: 5.3.0.6260
Attempting to build package from 'TestAutomation.EmsClient.csproj'.
MSBuild auto-detection: using msbuild version '16.3.1.50202' from 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\bin'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
Packing files from '
Using '
Add file '
Add file '
Id: [packageId]
Version: 1.0.0
Authors: [author]
Description: [description]
Project Url: [project url]
Dependencies: [package dependencies]
Added file '[Content_Types].xml'.
Added file '_rels/.rels'.
Added file 'lib/net45/[filename].dll'.
Added file 'lib/net45/[filename].dll.config'.
Added file 'lib/net45/[filename].pdb'.
Added file 'lib/net45/[filename].xml'.
Added file 'package/services/metadata/core-properties/edcb844ffd994895a7b2834f44e52f9a.psmdcp'.
Added file '[specfilename].nuspec'.
Successfully created package '[packagepath]'.
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:
Same NuGet version:
NuGet Version: 5.3.0.6260
Similar Error:
Successfully created package xxx . Error 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.5 to the nuspec - Add a dependency group for .NETFramework4.5.2 to the nuspec
Does not help with action referencing this document:
https://docs.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu5128
The same thing.
Noticed, that even if dependency group specified with targetPlatform, created .nupkg does not contains that groupping (tried 5.2, 5.3 versions). Also tried to pack with .nuspec target - did not observe that problem.
I suppose in version 5.2 warning was disabled.
also #2300
We have the same issue in our projects. It would be really nice to fix this issue.
I've recently encountered this issue, and setting up the dependency group (as per warning message) didn't help - like for other people in this thread.
I would be nice to have some fix for this.
Encountered same issue here.
Like all NuGet errors & warnings, we publish documentation giving more details than we can fit in the build message.
Please search for "NU5128" and it will lead you to our doc page: https://docs.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu5128
Please let us know if there is confusion after working through those examples and suggestions...(likely with some detail of your specific scenario and TFMs inside your Lib/Ref directories and which dependency groups you have in your nuspec)
Same issue here, already read the docs for this warning. Removing
Like all NuGet errors & warnings, we publish documentation giving more details than we can fit in the build message.
Please search for "NU5128" and it will lead you to our doc page: https://docs.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu5128Please let us know if there is confusion after working through those examples and suggestions...(likely with some detail of your specific scenario and TFMs inside your Lib/Ref directories and which dependency groups you have in your nuspec)
I have tried to do some action according to the doc you linked here while the warning is still there. It does not prevent publish a package but use a lower version NuGet help to resolve this warning/error.
@rrelyea , I've read through the documentation on the nu5128 warning before posting this issue and added group reference for .Net Framework 4.5 with the name suggested by Nuget, as you can see in step 5 of the reproduction steps, but the warning didn't go away. But when I downgraded Nuget to versions from 4.9 to 5.2 and packed the same binaries using the same configuration file the warning was not reported.
Can confirm. Got the same warning and found this thread. Downgraded to nuget.exe 5.2 and the warning went away.
I have the same issue with a .NET Standard 2 project. Downgrading to 5.2 removed the warning
We have the same problem using NuGet 5.4.0
We have the same problem using NuGet 5.4.0
Same issue with same version.
Like all NuGet errors & warnings, we publish documentation giving more details than we can fit in the build message.
@rrelyea - You do know that clear and properly descriptive error messages - and up to date documentation - have always been a problem with NuGet, right? Maybe its time to think about building some corrections for this into your processes, so that the tools you produce aren't so confusing, frustrating, and inconsistent.
EDIT: "Corrections" means that you should take the time to include clear and properly descriptive error messages, instead of what looks like an assumption that "it cannot be done, so not going to bother trying".
Same issue with NuGet Version: 5.4.0.6315
sample-nuget-package
.NET Framework 4.5
nuget pack -p Configuration=Release
NU5128
warningnuget push sample-nuget-package.1.0.0.nupkg
sample-nuget-consumer
.NET Framework 4.7.2
sample-nuget-package 1.0.0
<packages>
section of packages.config
: <package id="sample-nuget-package" version="1.0.0" targetFramework="net472" />
The package's targetFramework
is set to net472
when it should be net45
In sample-nuget-consumer.csproj
it seems to be ok:
<Reference Include="sample-nuget-package, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\sample-nuget-package.1.0.0\lib\net45\sample-nuget-package.dll</HintPath>
</Reference>
At least when telling Nuget to pack a .csproj file, it looks like this problem is ProjectFactory.ProcessDependencies always clears all dependency groups and puts back one with no target framework. Then when DependenciesGroupsForEachTFMRule.ExtractTFMsFromNuspec looks for TFMs in the dependency groups, it finds none. Therefore any file with TFM in the nupkg will trigger this warning?
Perhaps the solution is to make DependenciesGroupsForEachTFMRule
not log any warnings if it can't find any TFM?
In the mean time, I'm adding this to my nuget pack
command line:
-Properties NoWarn=NU5128
Getting this warning myself too. Scenario:
I am creating nuget packages for .Net Framework 4, 4.5 and 4 Client Profile assemblies of varying complexity. All three report the same error when I target a .csproj (nuget pack assembly.csproj
) but also create a .nuspec file of the same name in the same directory (as OP reported). I also get the error when I do not include a .nuspec file.
I add a framework reference to the .nuspec file as follows (TFM does not matter - full or short form, for any framework):
<?xml version="1.0" encoding="utf-8"?>
<package
xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>$author$</authors>
<description>$description$</description>
<copyright>$copyright$</copyright>
<dependencies>
<group targetFramework=".NETFramework4.0-Client" />
</dependencies>
</metadata>
</package>
The error is still reported, and the .nuspec file within the resultant .nupkg looks like this:
<dependencies />
If any dependencies are specified (or detected in the csproj), they are listed in the .nuspec within the resultant .nupkg, _without_ the targetFramework I have specified in the nuspec.
Input (though this is not required when targeting the .csproj file, as the output is the same regardless):
<dependencies>
<group targetFramework=".NETFramework4.5">
<dependency id="DependencyAssembly" version="0.0.1-preview20200406.2" />
</group>
</dependencies>
Output (in .nupkg file):
<dependencies>
<dependency id="DependencyAssembly" version="0.0.1-preview20200406.2" />
</dependencies>
I am using Nuget 5.4.0.6315 and packages.config.
However, the issue is not the warning itself - it is the resultant lack of package restrictions / rules when importing into another project; I can install these .Net 4.5 packages in a .Net 3.5 project - as long as there are generic /content
, /ref
or /lib
files, or <frameworkDependencies>
that exist without a TFM specified. Note that the nuget package that is generated creates /lib/<TFM>/<files>
containing the csproj's libraries as you would expect, and if you pass the -symbols
parameter, source code is output to /src
as desired.
Additional info:
If I target the .nuspec file instead of the .csproj file, I HAVE to specify -Properties NoWarn=NU5128
a hack at best, as the generated packages are not fit for purpose. Unfortunately, creating and targeting a .nuspec file is the only _option_ I can see that gives us the control we need at present.
Yes, I'd also rather the developers / client migrated to .Net Core to alleviate this burden, but unfortunately that is not an option in the short to medium term.
The documentation pointed by @rrelyea here worked for me as it directed me to add <SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
to the project file -- as it was just a Template NuGet package, I didn't want any framework dependency within it, and the _-_
file would just pollute it.
So, one thumb up to his answer. ;)
I've just run afoul of this in at least one of my xunit.fluently projects. Can someone advise, is there a workaround? It's been a little while for me, but if memory serves, I was forced to take additional measures in order to package these projects on account of dependencies on xunit.core
, cannot recall if that also means xunit
dependencies.
After perusing the responses here, downgrading may be the only valid path forward, at least until the issue has been resolved, at least in the near term. 馃憥 馃憥 馃憥 Longer range, _PLEASE FIX!_ 馃憤 馃憤 馃憤
I do't understand how this big issue is always present in version 5.9.
I tried on it and I have always the same issue unless it's ok with version 5.2.
Does someone know the "code" reason of this warning ?
Most helpful comment
@rrelyea , I've read through the documentation on the nu5128 warning before posting this issue and added group reference for .Net Framework 4.5 with the name suggested by Nuget, as you can see in step 5 of the reproduction steps, but the warning didn't go away. But when I downgraded Nuget to versions from 4.9 to 5.2 and packed the same binaries using the same configuration file the warning was not reported.