[英]How can I specify different dependencies for different versions of the .NET framework in a custom NuGet package?
I'm trying to create a NuGet package which has a dependency on System.Net.Http
(need the HttpClient). 我正在尝试创建一个依赖于
System.Net.Http
的NuGet包(需要HttpClient)。 For framework version 4.5.1, this assembly is a part of the BCL. 对于框架版本4.5.1,此程序集是BCL的一部分。 Hoewever, in 4.0 it is not.
Hoewever,在4.0中不是。 I believe it having compiling correctly with the proper conditional statements in the csproj.
我相信它已经正确编译了csproj中的正确条件语句。
The problem I'm currently wrestling with is that when I reference this package in a 4.5.1 project, it pulls in the dependency on Microsoft.Net.Http
. 我目前正在努力解决的问题是,当我在4.5.1项目中引用此包时,它会依赖于
Microsoft.Net.Http
。 I really only want to depend on Microsoft.Net.Http
for net40. 我真的只想依靠
Microsoft.Net.Http
来获取net40。
Here's my nuspec file: 这是我的nuspec文件:
<?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: 在VS中,NuGet包显示:
But again, I'm those dependencies are also being pulled in when using a project with target framework 4.5.1. 但同样,当使用带有目标框架4.5.1的项目时,我也会将这些依赖项纳入其中。 Which I don't want.
我不想要的。 Any help is appreciated.
任何帮助表示赞赏。
Need to be more specific when defining dependencies by framework 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>
Typical... after struggling with this for hours, I come up with the answer minutes after posting the question. 典型......在经历了数小时的努力之后,我在发布问题后得出了答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.