针对特定的依赖项 NuGet [英] Target specific dependencies NuGet

查看:33
本文介绍了针对特定的依赖项 NuGet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 .nuspec 文件中有以下依赖项:

I have the following dependencies in my .nuspec file:

<dependencies>
        <group>
          <dependency id="Dep1" version="2.4.11" />
          <dependency id="Dep2" version="1.0.4" />
          <dependency id="Dep3" version="1.0.4" />
          <dependency id="Dep4" version="1.0.0" />
          <dependency id="Dep5" version="1.0.4" />
          <dependency id="Dep6" version="1.0.4" />
        </group>
    </dependencies>

我已经创建了一个本地 nuget 服务器,我正在 Xamarin Forms 解决方案中安装这个 NuGet 包.

I've created a local nuget server and I'm installing this NuGet package in a Xamarin Forms solution.

问题是它会在解决方案的 Android 部分安装,但在 .netstandard 部分它会抱怨 Dep 4、5、6 仅适用于 MonoAndroid(这是正确的).我的 .netstandard 解决方案中不需要 dep 4,5 和 6.

The thing is that in the Android part of the solution it will install, but in the .netstandard part it will complain that Dep 4, 5, 6 are only for MonoAndroid (which is correct). I don't need the dep 4,5 and 6 in my .netstandard solution.

NU1202:Dep4 1.0.0 与 netstandard2.0 不兼容(.NETStandard,版本=v2.0).软件包 Dep4 1.0.0 支持:monoandroid10 (MonoAndroid,Version=v1.0) NU1202: Package Dep5 1.0.4 is与 netstandard2.0 (.NETStandard,Version=v2.0) 不兼容.包 Dep5 1.0.4 支持:monoandroid44 (MonoAndroid,Version=v4.4)

NU1202: Dep4 1.0.0 is not compatible with netstandard2.0 (.NETStandard,Version=v2.0). Package Dep4 1.0.0 supports: monoandroid10 (MonoAndroid,Version=v1.0) NU1202: Package Dep5 1.0.4 is not compatible with netstandard2.0 (.NETStandard,Version=v2.0). Package Dep5 1.0.4 supports: monoandroid44 (MonoAndroid,Version=v4.4)

如何分离每个 targetFramework 的依赖项?我在依赖项类别中尝试了多种组变体,但没有任何方法可以解决此问题.

How can I separate dependencies per targetFramework? I've tried multiple variations of groups within the dependencies category, but nothing will solve this problem.

推荐答案

通读后

https://docs.microsoft.com/en-us/nuget/reference/nuspec#dependencies-element

https://docs.microsoft.com/en-us/nuget/reference/target-frameworks

https://docs.microsoft.com/en-us/xamarin/cross-platform/app-fundamentals/nuget-manual

可以总结为:

2.0+ 版本

作为单个平面列表的替代方案,可以指定依赖项根据目标项目的框架配置文件使用.

As an alternative to a single flat list, dependencies can be specified according to the framework profile of the target project using elements within .

每个组都有一个名为 targetFramework 的属性并且包含零或更多元素.这些依赖是一起安装的当目标框架与项目的框架兼容时个人资料.

Each group has an attribute named targetFramework and contains zero or more elements. Those dependencies are installed together when the target framework is compatible with the project's framework profile.

没有targetFramework属性的元素被用作依赖项的默认或后备列表.请参阅目标框架确切的框架标识符.

The element without a targetFramework attribute is used as the default or fallback list of dependencies. See Target frameworks for the exact framework identifiers.

因此在我的情况下是:

    <dependencies>
       <group targetFramework="MonoAndroid10">
          <dependency id="Dep1" version="2.4.11" />
          <dependency id="Dep2" version="1.0.4" />
          <dependency id="Dep3" version="1.0.4" />
          <dependency id="Dep4" version="1.0.0" />
          <dependency id="Dep5" version="1.0.4" />
          <dependency id="Dep6" version="1.0.4" />
       </group>
       <group>
          <dependency id="Dep1" version="2.4.11" />
          <dependency id="Dep2" version="1.0.4" />
          <dependency id="Dep3" version="1.0.4" />
        </group>
    </dependencies>

这样,当我在 .netstandard 项目上安装包时,它会检查 targetFramework 并看到它不是 MonoAndroid,它将回退到没有 targetFramework 的元素,并且只使用 Dep1、Dep2 和 Dep3.对于 MonoAndroid10 项目,它将执行相同的操作并使用所有这些.

This way when I'm installing the package on the .netstandard project it will check the targetFramework and see that it's not MonoAndroid and it will fallback to the element without a targetFramework and use only Dep1, Dep2 and Dep3. For the MonoAndroid10 project it will do the same and use all of them.

这篇关于针对特定的依赖项 NuGet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆