我注意到,在创建新的 ASP.NET 5 项目时,有一个 src 目录,这对我来说完全有意义,因为我总是将所有解决方案的代码放在一个名为 source 的目录中.
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 文档中找到了以下内容:projects 属性指定哪些文件夹包含解决方案的源代码.默认情况下,项目结构将源文件放置在 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"
}
}
version
(以及可选的 runtime
和 architecture
)很重要,因为您的计算机有多个版本的 dnx.exe代码>.您可以检查
%USERPROFILE%.dnx
untimes
目录以查看所有已安装的运行时.global.json
的 "sdk"
部分从您安装的运行时之一定义 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
untimes
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
的 "projects"
部分很重要,它将在每个级别下的任何级别上扫描所有同级文件夹从目录.每个将被找到的 project.json
都将被解释为解决方案的项目.
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 的某些部分并将其放在解决方案层次结构的新子文件夹中.例如,您可以下载 Entity Framework 7 的 RC1 源代码(文件) 在新的 中解压压缩文件
文件夹.您会看到,在重新打开解决方案后不久,您的项目列表将越来越长,并且所有 Entity Framework 7 组件都将包含在您的解决方案中.以同样的方式,您可以在单独的目录 src
文件夹内的 efC:aspnetEF7
中提取下载的源并使用
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:aspnetEF7
and to use
{
"projects": [ "src", "c:/aspnet/EF7" ],
"sdk": {
"version": "1.0.0-rc1-update1"
}
}
您将获得相同的效果.如果您稍后决定删除调试 Entity Framework 7 的源代码,那么您应该从 global.json
中排除 "c:/aspnet/EF7"
,然后在 Visual Studio 中删除以前通过在解决方案视图中选择添加的项目,然后单击 Del 键.
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 组件的不同初步版本.如果您使用确切的依赖项,例如
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 包不兼容(至少因为在 beta 版本之间重命名了许多组件).为确保您的解决方案(您的所有项目)使用 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%NuGetNuGet.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%NuGetNuGet.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 feeds list
在这里有所帮助.您应该始终扫描项目层次结构中的所有 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
(您可以在 GitHub 或 MVC6 这里).您可以按照结构或选择其他位置并修改 global.json
的 "projects"
部分.
(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 Core 中使用.应该使用 dotnet.exe
代替.新的/修改的 global.json
和 project.json
的描述尚未完整记录.您可以在这里查看文档的初步版本.旧文档(位于 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.
这篇关于ASP.NET 5 中 Global.json 中项目部分的说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!