How to specify different dependencies for different versions of the .NET Framework in a custom NuGet package?

I am trying to create a NuGet package that is dependent on System.Net.Http (I need HttpClient). For Framework version 4.5.1, this assembly is part of BCL. However, in 4.0 this is not the case. I believe that he correctly compiled the correct conditional statements in csproj.

The problem that I am currently facing is that when I refer to this package in project 4.5.1, it pulls a dependency on Microsoft.Net.Http . I really only want to depend on Microsoft.Net.Http for net40.

Here is my nuspec file:

 <?xml version="1.0"?> <package> <metadata> <id>MyApp</id> <version>$version$</version> <title>MyApp</title> <authors>Me</authors> <owners>Me</owners> <requireLicenseAcceptance>false</requireLicenseAcceptance> <description>Description</description> <releaseNotes>Initial release</releaseNotes> <copyright>Copyright 2016</copyright> <dependencies> <group> <dependency id="Newtonsoft.Json" version="8.0.2"/> </group> <group targetFramework="net40"> <dependency id="Microsoft.Bcl" version="1.1.10" /> <dependency id="Microsoft.Bcl.Build" version="1.0.14" /> <dependency id="Microsoft.Net.Http" version="2.2.29" /> </group> </dependencies> </metadata> <files> <file src="bin\release\**\MyApp.dll" target="lib" /> </files> </package> 

In VS, the NuGet package shows this:

. NETFrameworkVersion = v4.0

But then again, I am also dependent when you use a project with a target structure of 4.5.1. Which I do not want. Any help is appreciated.

+6
source share
1 answer

You need to be more specific when defining dependencies by frame version.

 <?xml version="1.0"?> <package> <metadata> <id>MyApp</id> <version>$version$</version> <title>MyApp</title> <authors>Me</authors> <owners>Me</owners> <requireLicenseAcceptance>false</requireLicenseAcceptance> <description>Description</description> <releaseNotes>Initial release</releaseNotes> <copyright>Copyright 2016</copyright> <dependencies> <group targetFramework="net451"> <dependency id="Newtonsoft.Json" version="8.0.2"/> </group> <group targetFramework="net40"> <dependency id="Newtonsoft.Json" version="8.0.2"/> <dependency id="Microsoft.Bcl" version="1.1.10" /> <dependency id="Microsoft.Bcl.Build" version="1.0.14" /> <dependency id="Microsoft.Net.Http" version="2.2.29" /> </group> </dependencies> </metadata> <files> <file src="bin\release\**\MyApp.dll" target="lib" /> </files> </package> 

Both versions of the framework

Typically ... after I struggled with this for several hours, I come up with minutes of response after posting the question.

+4
source

All Articles