artganify
artganify

Reputation: 703

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. So I went ahead an specified the following in a .nuspec for one of my packages:

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

Upvotes: 4

Views: 3307

Answers (1)

Sergii Zhevzhyk
Sergii Zhevzhyk

Reputation: 4202

From the Nuget release documentation:

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.

It means that if the project uses net45, net40-client or later - no dependencies will be installed.

The group element without the targetFramework attribute is used to install the dependencies for an early version of these frameworks (for example, net20).

A good example from the Nuget release documentation:

<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. If the package is installed into a project that targets .NET 4.0 or later, two dependencies, jQuery and WebActivator, will be installed. 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.

Upvotes: 1

Related Questions