0

I was just looking at the project.json file in one of my ASP.NET Core projects and noticed there are two different areas to list dependencies.

One inside the frameworks node and the other is a dependencies node. Why/when would/should you place the dependencies in one location over the other?

{
    "version": "1.0.0-*",
    "description": "My Class Library",
    "authors": [ "" ],
    "tags": [ "" ],
    "projectUrl": "",
    "licenseUrl": "",
    "frameworks": {
        "dotnet5.4": {
            "dependencies": {
                "Microsoft.CSharp": "4.0.1-beta-23516",
                "System.Collections": "4.0.11-beta-23516",
                "System.Linq": "4.0.1-beta-23516",
                "System.Runtime": "4.0.21-beta-23516",
                "System.Threading": "4.0.11-beta-23516"
            }
        }
    },
    "dependencies": {
        "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final"
    }
}
janhartmann
  • 14,713
  • 15
  • 82
  • 138
Matthew Verstraete
  • 6,335
  • 22
  • 67
  • 123

1 Answers1

0

The reason is very easy. You can have different dependencies for different frameworks.

In some cases the specified dependence exist in different versions for different frameworks.

In another case the specified dependency like System.Runtime needed be not included as all. The problem is here the DLL is separate module in .NET Core (see here), but the dnx46 or dnx451 contains the implemented methods inside of .Net framework. One don't need to include no external (additional) dll. Thus you need don't include System.Runtime package in the the dnx451 part of the dependencies or as the common dependency. Thus System.Runtime is framework-specific dependencies.

In some seldom cases you can include the dependency in the form "dnx451": "frameworkAssemblies": { "System.Runtime": "" }} to skip including of System.Runtime if it was erroneously required (see the question). Typically one uses frameworkAssemblies to reference to assemblies from Global Assembly Cache (GAC) without redistributing it (see the documentation).

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • I understand that if your targeting multiple frameworks you can specify different versions for each framework. But what about the pure `dependencies` node that is not tied to any framework? – Matthew Verstraete Jan 26 '16 at 16:19
  • @MatthewVerstraete: It's **common** dependency used for every targeting framework. For example `EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final"` is not included as the part of some framework and the package supports `dotnet5.4`, `dnx451` and `dnxcore50`. Thus you can include it as common dependency. – Oleg Jan 26 '16 at 16:24
  • I see, can you amend your answer for that so it address both parts of the question? – Matthew Verstraete Jan 26 '16 at 18:41
  • @MatthewVerstraete: Sorry, but I don't understand what you mean. What "both parts of the question" you mean? `project.json` have two places for including dependencies: `"dependencies"` includes common dependencies over all `"frameworks"` which you use and `"frameworks"."frameworkName"."dependencies"` includes dependencies which are used only during building the target for the specified framework. I prescribed examples when such framework-specific dependencies could be required. – Oleg Jan 26 '16 at 19:13
  • You answer explains why there is a dependencies section for the framework node but does not explain the usage of the dependences node by it's self. – Matthew Verstraete Jan 26 '16 at 19:23
  • @MatthewVerstraete: Could you be more precise? You wrote "the dependencies node by it's self". What you mean? It doesn't exist. It seems that you still misunderstand what `dependencies` do, but I can't help you because you express yourself not clear enough and I have to guess what you mean. – Oleg Jan 27 '16 at 06:39
  • If you look at the code I posted there is a `frameworks` node that has it's own `dependencies` node (frameworks -> dotnet5.4 => dependencies). After that node there is just `dependencies` – Matthew Verstraete Jan 27 '16 at 18:55