Nuget 是否支持与特定平台相关的依赖项?
我有一个库,我想为其创建一个 Nuget 包,该包具有以下情况:
该库编译为不同的版本:
- Silverlight 4.0
- .Net 4.0
- .net 3.5
- Windows Phone
幸运的是,所有这些平台都受 Nuget 支持,因此在我的包的 lib 文件夹中,我可以为每个平台创建子文件夹,当库打开时,Nuget 会做正确的事情安装在任何这些平台上。
问题是我还有一些其他依赖项,这些依赖项因平台而异。例如:在 Windows Phone 上,我需要包含第 3 方 zip 库 (wpSharpLibZip),但在包含压缩实用程序的其他平台上不存在此依赖性。
Nuget 支持这种情况吗?我希望能够让 wpSharpLibZip 依赖项仅存在于 Windows Phone 平台上。我是否必须为每个平台创建一个单独的包?
如果此功能不存在,我可以想象它的实现方式如下:
更改包清单的部分以支持:
<dependencies>
<dependency id="Newtonsoft.Json" version="3.5.8" />
<dependency id="wpSharpLibZip">
<platform>Silverlight 4.0 - Windows Phone</platform>
</dependency>
</dependencies>
或者另一种方法是允许每个平台文件夹内(在 lib 文件夹下)有一个单独的 .nuspec 文件这可以阐明平台特定的依赖关系。
I have a library which I want to create a Nuget package for which has the following situation:
The library compiles to different versions:
- Silverlight 4.0
- .Net 4.0
- .net 3.5
- Windows Phone
Luckily all of these platforms are supported by Nuget so in the lib folder of my package I can create sub folders for each of these platforms and Nuget will do the right thing when the library is installed on any of those platforms.
The problem is I have some other dependencies which differ by platform. For example: On the Windows Phone I need to include a 3rd party zip library (wpSharpLibZip) but this dependency does not exist on the other platforms which have zipping utilities included.
Is this scenario supported in Nuget? I want to be able to have the wpSharpLibZip dependency to only exist on the Windows Phone platform. Do I have to just create a separate package per platform?
If this feature doesn't exist I could imagine it being implemented something like:
Changing the section of the package manifest to support:
<dependencies>
<dependency id="Newtonsoft.Json" version="3.5.8" />
<dependency id="wpSharpLibZip">
<platform>Silverlight 4.0 - Windows Phone</platform>
</dependency>
</dependencies>
Or another way could be to allow for a seperate .nuspec file inside of each platform folder (under the lib folder) which could spell out platform specific dependencies.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每个不同的依赖项集都有单独的包。依赖关系是包级别的。 NuGet 目前不支持这种情况,并且可能暂时不支持(如果有的话)。
更新:从 NuGet 2.x 开始,依赖项就有组,因此您可以通过这种方式设置依赖项。请参阅 https://docs.nuget。 org/create/nuspec-reference#specifying-dependency-in-version-2.0-and-above 了解详细信息
Separate package for each different dependency set. Dependencies are package level. NuGet doesn't support this scenario at this time and may not for awhile if at all.
UPDATE: Dependencies have groups since NuGet 2.x, so you can set dependencies this way. See https://docs.nuget.org/create/nuspec-reference#specifying-dependencies-in-version-2.0-and-above for details