Quantcast
Channel: Active questions tagged nuget-package - Stack Overflow
Viewing all articles
Browse latest Browse all 3067

Nuget packing of a project file fails when using dependency groups to target multiple frameworks

$
0
0

Nuget is driving me nuts...I have a class library which needs to be consumed by various target frameworks.We are also using a nuspec file (reasons beyond this post) and therefor we use dependency groups.

When I do a nuget pack xxx.nuspec everything builds fine and nuget is happy.

However, when I do a nuget pack xxx.csproj the nuget pack fails with a message "an item with the same key has already been added".

It looks as if nuget tries to add the generate output assembly multiple times.

I've added IncludeBuildOutput=false to the csproj file to no avail.

Everything works when I use dotnet pack instead of nuget pack. So I wonder :

Is it possible to use dependency groups for targeting various frameworks in .nuspec file at all when using nuget.exe?

(Please note that the behaviour I see is different from NuGet Dependency Framework Targeting not working when packaging using the .csproj. I specifically hit a problem that the generated output assembly is being added multiple times and can't tell nuget (yet) to ignore that.)

Steps to reproduce.

1 : Create a test class library and add to the csproj IncludeBuildOutput=false and a reference to a nuspec file

<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><TargetFramework>netcoreapp3.1</TargetFramework><IncludeBuildOutput>false</IncludeBuildOutput></PropertyGroup></Project>

2 : Add a nuspec and add dependency groupstargeting various frameworks

<?xml version="1.0" encoding="utf-8"?><package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"><metadata><id>Test.Class.Library.20230121</id><version>$version$</version><title>Test class library</title><authors>Me</authors><owners>Me</owners><projectUrl>https://myportal/SitePages/Home.aspx</projectUrl><requireLicenseAcceptance>false</requireLicenseAcceptance><description>test nuget pack</description><dependencies><group targetFramework=".NETCoreApp3.1" ><dependency id="Serilog.Sinks.Async" version="1.5.0" /></group><group targetFramework=".NETStandard2.0" ><dependency id="Serilog.Sinks.Async" version="1.5.0" /></group><group targetFramework=".NETStandard2.1" ><dependency id="Serilog.Sinks.Async" version="1.5.0" /></group></dependencies></metadata></package>

Viewing all articles
Browse latest Browse all 3067

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>