NuGet Dependencies Conditional on Runtime?

Feb 24, 2011 at 6:50 PM

Nuget has a mechanism to included libraries for different versions of the runtime, but is there a mechanism for dependencies only needed for specific version of the runtime? 

For example you have a library that you are creating a nuspec for and it has a dependency for another library that is in nuget but is 4.0 only, but your library has been crudely backported 2.0 without that dependency. So in your lib folder it's good with net20 and net40, but without being able to specify that the dependency is only needed for 4.0 your package will fail on 2.0 because it will try to install the unnecessary dependency.

Coordinator
Feb 24, 2011 at 6:52 PM

We don’t have that ability today. For now, create 2 packages. One for 2.0 and one for 4.0.

Feb 24, 2011 at 6:58 PM

Could you log a bug so it is tracked? One way to do this would be to allow an optional framework to be specified on the <dependency> tag, just like we're planning to do with our new GAC reference feature.

Although I wonder if a simpler solution is to just not fail in this case. So basically:

  • When the primary package you're trying to install doesn't have anything for your framework, fail
  • But when that happens for for dependent package, allow the dependent package not to bring in anything

@techekon: can you paste the output with the error that you're getting from the NuGet console?

Feb 24, 2011 at 7:40 PM
davidebbo wrote:

Could you log a bug so it is tracked? One way to do this would be to allow an optional framework to be specified on the <dependency> tag, just like we're planning to do with our new GAC reference feature.

Although I wonder if a simpler solution is to just not fail in this case. So basically:

  • When the primary package you're trying to install doesn't have anything for your framework, fail
  • But when that happens for for dependent package, allow the dependent package not to bring in anything

@techekon: can you paste the output with the error that you're getting from the NuGet console?

I think I found a issue logged in there already for the general case of having dependencies with a target framework specified, http://nuget.codeplex.com/workitem/697 

This is the error and I think it is a correct error:

Install-Package : Unable to find assembly references that are compatible with the target framework '.NETFramework,Version=v3.5'.
At line:1 char:16
+ install-package <<<<  NET35_W_40_DEP
    + CategoryInfo          : NotSpecified: (:) [Install-Package], InvalidOperationException
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.Cmdlets.InstallPackageCmdlet

If you ignore it, sure it would work for my back ported version but I don't think you can assume that was then intention. Also what if my backported version requires an additional assembly then the 4.0 version is going to end up having unnecessary package included.

http://nuget.codeplex.com/documentation?title=Creating%20a%20Package:

Supporting Multiple .NET Framework Versions and Profiles

Many libraries target a specific version of the .NET Framework. For example, you might have one version of your library that’s specific to Silverlight, and another version of the same library that takes advantage of .NET Framework 4 features. You do not need to create separate packages for each of these versions. NuGet supports putting multiple versions of the same library in a single package keeping them in separate folders within the package.

If a single package is supposed to support multiple target frameworks, it seems logical that you should be able to specify it on dependencies as well the included libs and it should probably follow the same logic as the assemblies included package in the package. So if you specify net40 on a dependency that should be the only dependency for a net40 installation and if you have 2nd dependency for a general case but it should be included in a net40 too you have specify the dependency twice once with net40 and once without.