简体   繁体   English

当未指定'targetFramework'属性时,Nuget不会安装依赖项

[英]Nuget doesn't install dependencies when 'targetFramework' attribute isn't specified

According to the nuspec reference chapter "Specifying Dependencies in version 2.0 and above", it's possible to declare a dependency in a group element without an additional targetFramework attribute, which implies that this dependency is valid for all frameworks. 根据nuspec参考章节“在版本2.0及更高版本中指定依赖关系”,可以在没有其他targetFramework属性的group元素中声明dependency ,这意味着此依赖关系对所有框架都有效。 So I went ahead an specified the following in a .nuspec for one of my packages: 所以我在我的一个软件包的.nuspec中指定了以下内容:

<dependencies>
  <group>
    <dependency id="DEPENDENCY" version="1.0.0" />
  </group>

  <group targetFramework="net40-client">
  </group>

  <group targetFramework="net45">
  </group>
</dependencies>

After installing the package in one of my projects, the dependency isn't there at all. 在我的一个项目中安装软件包后,依赖项根本就不存在。 Neither in the project references nor in the packages folder in the root of my project. 既不在项目引用中,也不在我项目根目录中的packages文件夹中。 However when doing this: 但是这样做时:

<dependencies>
  <group targetFramework="net40-client">
    <dependency id="DEPENDENCY" version="1.0.0" />
  </group>

  <group targetFramework="net45">
    <dependency id="DEPENDENCY" version="1.0.0" />
  </group>
</dependencies>

... it works flawlessly. ......它完美无瑕。

Is this a bug? 这是一个错误吗? ~~Do I possibly override the 'global' dependency configuration with the empty local declarations?~~ Or did I misunderstood something here? ~~我可能用空的本地声明覆盖'全局'依赖配置吗?~~或者我在这里误解了什么?


EDIT 编辑

It's possible to declare empty dependency elements and still have 'a global one': https://github.com/dsplaisted/PCLStorage/blob/master/common/PCLStorage.nuspec 可以声明空的依赖元素并且仍然具有“全局依赖元素”: https//github.com/dsplaisted/PCLStorage/blob/master/common/PCLStorage.nuspec

From the Nuget release documentation : Nuget发布文档

There is no inheritance between groups. 组之间没有继承。 If a project's target framework matches the targetFramework attribute of a group, only the dependencies within that group will be installed. 如果项目的目标框架与组的targetFramework属性匹配,则仅安装该组中的依赖项。

It means that if the project uses net45 , net40-client or later - no dependencies will be installed. 这意味着如果项目使用net45net40-client或更高版本 - 将不会安装任何依赖项。

The group element without the targetFramework attribute is used to install the dependencies for an early version of these frameworks (for example, net20 ). 没有targetFramework属性的group元素用于安装这些框架的早期版本的依赖项(例如, net20 )。

A good example from the Nuget release documentation : Nuget发布文档中的一个很好的例子:

<dependencies> 
   <group>
      <dependency id="RouteMagic" version="1.1.0" />
   </group>

   <group targetFramework="net40">
      <dependency id="jQuery" />
      <dependency id="WebActivator" />
   </group>

   <group targetFramework="sl30">
   </group>
</dependencies>

Note that a group can contain zero dependencies. 请注意,组可以包含零依赖项。 In the example above, if the package is installed into a project that targets Silverlight 3.0 or later, no dependencies will be installed. 在上面的示例中,如果将软件包安装到面向Silverlight 3.0或更高版本的项目中,则不会安装任何依赖项。 If the package is installed into a project that targets .NET 4.0 or later, two dependencies, jQuery and WebActivator, will be installed. 如果将软件包安装到面向.NET 4.0或更高版本的项目中,则将安装两个依赖项jQuery和WebActivator。 If the package is installed into a project that targets an early version of these 2 frameworks, or any other framework, RouteMagic 1.1.0 will be installed. 如果将软件包安装到针对这两个框架的早期版本或任何其他框架的项目中,则将安装RouteMagic 1.1.0。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM