Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

confused about dependencies in project.json

in project.json files we have a dependencies section and then we also have a frameworks section where under each framework there can be more dependencies. I'm confused about why sometimes dependencies need to go in the framework sections and other times in the main dependencies section?

for example in several of my projects I have dependencies under dnxcore50 but when I upgrade them from nuget it puts the upgraded version in the main dependencies section and leaves the old one with a lower version under the frameworks section.

In general I'm finding it is very easy to make mistakes and get weird dependency resolution errors in VS 2015 for one framework or another and it is difficult figuring out what caused the error. I've had times where I add a dependency in one project and that causes errors in another project with types found in more than one package in the chain or problems resolving basic primitive types.

It seems like VS 2015 templates may put them in different places vs when you add a reference with nuget, or maybe because I'm using beta5 the tooling in VS is a little out of sync.

Is there any guidance for when to put dependencies in the main dependencies section vs under the framework specific sections?

like image 338
Joe Audette Avatar asked Feb 09 '23 13:02

Joe Audette


1 Answers

The reason why you can do framework specific dependencies is that some packages don't support all the frameworks.

The most common case are the NuGet packages that don't support CoreCLR (yet). Some prefer to use alternatives on that framework rather than not supporting it. Therefore, on desktop CLR (dnx451), they use one NuGet package, while on CoreCLR they use another one.

A concrete example for that is in dnu. While running on desktop CLR it uses System.Net.Http. However, on CoreCLR it uses Microsoft.Net.Http.Client: https://github.com/aspnet/dnx/blob/dev/src/Microsoft.Framework.PackageManager/project.json#L29

You might also notice in the file above that we use dependencies and frameworkAssemblies. That's another reason why you would use different packages from different targets. frameworkAssemblies come from the GAC and it only works for desktop CLR.

Therefore, the rule is: use the top level dependencies property when you have packages that will be used by all frameworks that you package supports.

like image 95
Victor Hurdugaci Avatar answered Feb 20 '23 11:02

Victor Hurdugaci