问题描述
在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?
例如,在我的几个项目中,我在dnxcore50下具有依赖项,但是当我从nuget升级它们时,会将升级版本放在主要依赖项部分中,而将旧版本放在较低的框架下.
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.
总的来说,我发现在VS 2015中针对一个框架或另一个框架犯错误并获得奇怪的依赖关系解析错误非常容易,而且很难找出导致错误的原因.有时候,我会在一个项目中添加一个依赖项,而这会导致另一个项目中的错误,而该错误的原因是链中多个包中发现了类型,或者解决了基本基本类型的问题.
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.
与使用nuget添加引用相比,VS 2015模板似乎将它们放置在不同的位置,或者可能是因为我使用beta5时VS中的工具有点不同步.
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?
推荐答案
之所以可以使用框架特定的依赖项,是因为某些软件包不支持所有框架.
The reason why you can do framework specific dependencies is that some packages don't support all the frameworks.
最常见的情况是尚不支持CoreCLR的NuGet软件包.有些人更喜欢在该框架上使用替代方案,而不是不支持它.因此,在台式机CLR(dnx451)上,它们使用一个NuGet软件包,而在CoreCLR上,它们使用另一个软件包.
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.
具体示例在 dnu
中.在桌面CLR上运行时,它使用 System.Net.Http
.但是,在CoreCLR上,它使用 Microsoft.Net.Http.Client
:
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
您可能还会在上面的文件中注意到我们使用了依赖项
和 frameworkAssemblies
.这就是为什么要使用来自不同目标的不同软件包的另一个原因. frameworkAssemblies
来自GAC,它仅适用于桌面CLR.
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.
这篇关于对project.json中的依赖项感到困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!