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

查看:85
本文介绍了定位特定的依赖项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,Version = v2.0)不兼容。软件包Dep4 1.0.0支持:
monoandroid10(MonoAndroid,Version = v1.0)NU1202:软件包Dep5 1.0.4是
与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 -元素

https://docs.microsoft.com/zh-cn/nuget/reference/target-frameworks

> https://docs.microsoft.com/zh-CN/xamarin / cross-platform / app-fundamentals / nuget-manual

它可以总计为:


版本2.0 +

Version 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.

因此,在我的情况下为:

Therefore in my case it would be:

    <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天全站免登陆