在Global.json在ASP.NET项目部分的说明5 [英] Explanation of the projects section in Global.json in ASP.NET 5

查看:1599
本文介绍了在Global.json在ASP.NET项目部分的说明5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,创建一个新的ASP.NET项目5时,有一个src目录这完全是有道理的我,因为我一直把我的解决方案的code在一个名为源目录。

I noticed that when creating a new ASP.NET 5 project there is a src directory which completely makes sense to me since I have always put all of my solution's code in a directory called source.

我注意到有一个名为global.json它默认中有如下内容:

I noticed there is a file called global.json which by default has the following content in it:

{
  "projects": [ "src", "test" ],
  "sdk": {
    "version": "1.0.0-rc1-update1"
  }
}

我找到了ASP.NET 5文档中的以下内容:
该项目的属性指定哪些文件夹包含源$ C ​​$ C的解决方案。默认情况下,项目结构将源文件放在一个src文件夹,从而构建工件放置在同级文件夹中,使其更容易从源代码控制排除这样的事情。

I found the following in the ASP.NET 5 documentation: The projects property designates which folders contain source code for the solution. By default the project structure places source files in a src folder, allowing build artifacts to be placed in a sibling folder, making it easier to exclude such things from source control.

然而,这是该项目的结构,我的想法(这基本上将是我想要的同一个解决方案下的2个大型项目):

However, here is the project structure that I have in mind (It is basically going to be 2 large projects that I want under the same solution):

MySolution
    MySolutionProject1Src
        client
            p1.WebAPI
        business
            p1.Business
            p1.Model
        data
            p1.Repository
        test
            p1.BusinessTests
            p1.WebAPITests


    MySolutionProject2Src
        client
            p2.Web
        business
            p2.Business
            p2.Model
        data
            p2.Repository
        test
            p2.BusinessTests

所以,我将更新global.json为以下? (每个父目录):

So would I update global.json to be the following? (one for each parent directory):

{
  "projects": [ "MySolutionProject1Src", "MySolutionProject2Src" ],
  "sdk": {
    "version": "1.0.0-rc1-update1"
  }
}

还是应(为每一个子目录一个)更多的东西是这样的:

or should it be something more like this (one for every single sub-directory):

{
  "projects": [ "MySolutionProject1Src/client", "MySolutionProject1Src/business", "MySolutionProject1Src/data" "MySolutionProject1Src/test", "MySolutionProject2Src/client", "MySolutionProject2Src/business", "MySolutionProject2Src/data" "MySolutionProject2Src/test" ],
  "sdk": {
    "version": "1.0.0-rc1-update1"
  }
}

或者我应该只是简单地把它作为SRC,并把一切都为子文件夹在src ..

Or should I simply just leave it as "src" and put everything as sub folders under src..

我假设我可以创造我想要的任何解决方案的结构,但我关心的是规则来更新global.json项目部分匹配它的时候跟随。基于文档上说,一个文物文件夹将在指定global.json每个路径创建。所以我想知道如果我想在溶液或只是一个大一个在外面的每一个项目的文物文件夹中。

I am assuming I can create whatever solution structure I want, but my concern is the rules to follow when updating the global.json projects section to match it. Based on the documentation it says an artifacts folder will be created for each path specified in global.json. So I am wondering if I want an artifacts folder for every single project in the solution or just one big one on the outside.

推荐答案

首先我会转发你的文档,它描述了 global.json 部分。

First of all I would forward you to the part of documentation, which describes global.json.

{
  "projects": [ "src", "test" ],
  "sdk": {
        "version": "1.0.0-beta5",
        "runtime": "clr",
        "architecture": "x86"
  }
}

版本(可选择运行架构 ),因为你的电脑有 dnx.exe 的多个版本是很重要的。您可以检查%USERPROFILE%\\。DNX \\运行时间目录以查看所有已安装运行时。的SDK部分 global.json 定义的dnx.exe 从中安装运行时环境中的一个。

The version (and optionally runtime and architecture) are important because your computer have multiple versions of dnx.exe. You can examine %USERPROFILE%\.dnx\runtimes directory to see all the installed runtimes. The "sdk" part of global.json defines the version of dnx.exe from one of the runtimes which you installed.

要了解关于项目是很重要的 global.json 的一部分,它会被扫描的所有同级文件夹从目录下的每一个的水平。每个 project.json ,它会被发现,将PTED作为解决方案的项目间$ P $。

It's important to understand about "projects" part of global.json that it will be scanned all sibling folders on any level under every from the directory. Every project.json, which will be found, will be interpreted as the project of the solution.

例如,您可以下载ASP.NET的某些部分,并将其放置在您的解决方案层次的新的子文件夹。例如,您可以下载 RC1 实体框架7(的的文件)任何提取新的的src 项目的文件夹内> EF 文件夹中。你会看到解决方案的重启之后,很短的时间,你的项目名单将更长,更长和所有实体框架7组件将包含在您的解决方案。以同样的方式你可以提取单独的目录下载的源 C:\\ ASPNET \\ EF7 和使用

You can for example download some part of ASP.NET and place it in the new subfolder of your solution hierarchy. For example you can download RC1 source of Entity Framework 7 (the file) any extract the zip-file in new ef folder inside of src folder of your project. You will see that, short time after reopening of the solution, the list of your project will be longer and longer and all Entity Framework 7 components will be included in your solution. In the same way you can extract the downloaded sources in separate directory C:\aspnet\EF7 and to use

{
  "projects": [ "src", "c:/aspnet/EF7" ],
  "sdk": {
    "version": "1.0.0-rc1-update1"
  }
}

您将有同样的效果。如果您以后决定删除调试实体框架7的来源,那么你应该只排除C:/ ASPNET / EF7 global.json ,然后在Visual Studio中通过选择在解决方案视图中删除previously添加项目,然后点击<大骨节病>删除键。

You will have the same effects. If you later decide to remove debugging the sources of Entity Framework 7 then you should just exclude "c:/aspnet/EF7" from global.json and then remove in Visual Studio previously added projects by selection in Solution View and click Del key.

我认为,它应该清楚,你在文件夹结构有准备。

I think that it should clear the possibilities which you have in the folder structures.

还有一个非常重要的可选的文件,它可以在溶液中存在的层次结构,是 NuGet.config 文件。它定义的NuGet饲料,其中包将被加载。问题是,还有的许多的的NuGet库(见答案),其中有 ASP.NET 5组件的不同preliminary版本的。如果您使用确切依赖像

One more very important optional file, which could exist in the solution hierarchy, is NuGet.config file. It defines NuGet feed, where the packages will be loaded. The problem is that there are many NuGet repositories (see the answer), which have different preliminary versions of ASP.NET 5 components. If you use the exact dependencies like

"EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final"

再一个只需要在该库的NuGet明确的版本。问题是,有时候一个人使用依赖像

then one need just have the explicit version in the NuGet repository. The problem is that sometimes one uses the dependency like

"EntityFramework.MicrosoftSqlServer": "7.0.0-*"

加载包的最新版本。如果你会使用错误的NuGet饲料那么你就可以得到早期RC2版本,这是与其他RC1包(至少是因为测试版本之间的许多组件的重新命名的)不兼容。为了确保您的解决方案(所有项目)使用RC1您可以将您的解决方案文件夹下面的 NuGet.config (所有项目的顶部),例如以下内容

to load the latest build of the package. If you would use wrong NuGet feed then you can get early RC2 builds, which are incompatible with other RC1 packages (at least because of renaming of many components between beta versions). To be sure that your solution (all your projects) uses RC1 you can place the following NuGet.config in your solution folder (on top of all projects) for example the following content

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageRestore>
    <clear /> <!-- ensure only the sources defined below are used -->
    <add key="automatic" value="False" />
  </packageRestore>
  <packageSources>
    <add key="AspNetVNext" value="https://www.myget.org/F/aspnetmaster/api/v3/index.json" />
    <add key="NuGet" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
  <activePackageSource>
    <add key="AspNetVNext" value="true"  />
    <add key="NuGet" value="true"  />
  </activePackageSource>
</configuration>

请参阅文档。我建议你​​在某些项目文件夹中打开命令行并执行

See the documentation. I recommend you to open command line in some project folder and to execute

dnu feeds list

命令。它会显示所有的 NuGet.config 从当前和父文件夹和全局文件%APPDATA%\\的NuGet \\ NuGet.Config 合并即可。的NuGet将搜索在所有活动资料库的包。这将是 https://api.nuget.org/v3/index.json https://www.myget.org/F/aspnetmaster/api/v3 /index.json 在上述情况下

command. It will shows that all the NuGet.config from the current and the parent folders and the global file %appdata%\NuGet\NuGet.Config will be combined. NuGet will be search for packages in on all active repositories. It will be https://api.nuget.org/v3/index.json and https://www.myget.org/F/aspnetmaster/api/v3/index.json in the above case.

可能发生的冲突可能是,如果多个 NuGet.config 存在,分不同的NuGet饲料或启用/禁用一些饲料。命令 DNU提要列表帮助在这里。你应该总是扫描项目中的层次结构,以prevent所有 NuGet.config 文件/解决冲突。许多冲突的解决构成大多是在正确的饲料的使用或明确版本的软件包分辨率的使用。

Possible conflicts could be if multiple NuGet.config exist, points different NuGet feeds or enable/disable some feeds. The command dnu feeds list helps here. You should always scan for all NuGet.config files in your project hierarchy to prevent/resolve the conflicts. The resolution of many conflicts consist mostly in usage of correct feeds or the usage of explicit versions for resolution of packages.

我建议您阅读文章,它描述的NuGet配置继承

I recommend you to read the article, which describes NuGet Configuration Inheritance.

我希望你能决定哪些结构将是现有环境更好。我会向你推荐持有的标准结构

I hope that you could decide which structure would be better for your existing environment. I would you recommend to hold the standard structure

solution
    src
        project
        folderWithProjects

和放置 global.json 在解决方案目录和 NuGet.config 。为测试项目的默认位置:从主要项目分开:

and to place global.json and NuGet.config in the solution directory. The default place for the test-projects: separate from the main projects:

solution
    src
        project
        folderWithProjects
    test
        testproject1
        testproject2

(您可以检查实体框架7对 GitHub的或MVC6的这里)。您可以按照结构或选择其他位置并修改项目的一部分 global.json

(you can examine the structure of Entity Framework 7 on GitHub or MVC6 here). You can follow the structure or to choose another location and to modify "projects" part of the global.json.

更新:微软做了很多RC1和RC2之间的变化。 Dnx.exe 将不多于ASP.NET核心使用。每个人都应该使用 dotnet.exe 来代替。新的/修改 global.json project.json 还没有充分记录的描述。你可以看到文档 rel=\"nofollow\">的preliminary版本。在旧文档的链接(在 https://docs.asp.net/en/latest/dnx )现在打破。

UPDATED: Microsoft made a lot of changes between RC1 and RC2. Dnx.exe will be not more used in ASP.NET Core. One should use dotnet.exe instead. The description of new/modified global.json and project.json are not yet full documented. You can see the preliminary version of the documentation here. The links on the old documentation (under https://docs.asp.net/en/latest/dnx) are now broken.

这篇关于在Global.json在ASP.NET项目部分的说明5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆