.NET Core - 解决方案、框架、导入、运行时 [英] .NET Core - solutions, frameworks, imports, runtimes

查看:23
本文介绍了.NET Core - 解决方案、框架、导入、运行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开始重新设计一组框架库以使用 .NET Core.以为我会等待 RC2 并热衷于陷入困境.

I'm starting the process of reworking a framework set of libraries to use .NET Core. Thought I'd wait for RC2 and keen to get stuck in.

我正借此机会近距离接触构建系统、配置、从头开始编写所有代码,以获得更深入的理解,并且没有我不想要/不需要的不必要的包袱.然而,缺乏文档使这变得非常困难..所以我想在这里问一下,毫无疑问聪明的 .NET Core 人藏在哪里 ;)

I'm taking the opportunity to get up close and personal with the build system, configs, code everything from scratch to get a deeper understanding and have no unnecessary baggage that I don't want/need. However, the lack of documentation makes this quite difficult.. so I wanted to ask here, where no doubt clever .NET Core folks are hiding ;)

我知道这个问题很长并且有很多子问题.但是,我觉得可以通过指向文档的单个链接或知情人士的几行简洁文字来回答.感谢您的耐心等待,我希望这可能成为其他同行的有用答案资源,试图了解 .NET Core 的好方法.

I know this question is long and has lots of sub-questions. But it could be answered I feel by a single link to documentation, or a few succint lines from someone in the know. Thanks for bearing with me, and I hope that this might become a useful answer resource for others in the same boat, trying to understand a good approach for .NET Core.

首先,global.json.我希望在同一个解决方案"中有多个项目和组件.通过另一个 SO 问题,我发现了这个隐藏链接:http://dotnet.github.io/docs/project-model/global-json-reference.html - 但似乎没有用于从头开始设置或使用它的 VS 工具.

First, global.json. I want multiple projects and components in the same 'solution'. Through another SO question I found this hidden link: http://dotnet.github.io/docs/project-model/global-json-reference.html - but there seems to be no VS tooling for setting up or using this from scratch.

1) global.json 问题

A) 这些文档指的是什么构建系统?dotnet 构建?(帮助说明它只是构建一个项目 - 如果它执行解决方案" - 如果它仍然是名称 - 它是否只是在所有子文件夹上运行 dotnet build ?).

A) What build system do these docs refer to? dotnet build? (The help for that says it just builds a project - if it does 'solutions' - if that's still the name - does it just run dotnet build over all child folders?).

B) 周围的许多示例都有一个 "sdk" 属性 - 但 EF Core 没有它,并且新的单句风格"文档没有提到它.ASP.NET Core 的官方 RC2 迁移指南有它 还在吗或不?如果是这样,为什么需要它?它有什么用?它有哪些选择?

B) Many examples around have an "sdk" property - but EF Core doesn't have it, and the new "single-sentence-style" docs don't refer to it. The official RC2 migration guide for ASP.NET Core has it Is it still around or not? If so, why is it needed? What uses it? What are the options for it?

接下来是 project.json 和框架.我想了解这里的框架选项.有清单吗?官方指导?dotnet new 使用 netcoreapp1.0;官方文档"使用dnxcore50的例子并且上个月的GH讨论也提出了netcore1.0的问题作为框架(相对于应用)的可能性.

Next up, to project.json and frameworks. I want to understand the options here for frameworks. Is there a list? Official guidance? dotnet new uses netcoreapp1.0; "official docs" use an example of dnxcore50 and this GH discussion from last month also raises the question of netcore1.0 as a possibility for frameworks (vs apps).

此外,导入.我对命名感到非常困惑 - 文档说这是该项目兼容的其他框架的列表..

Furthermore, imports. Am quite baffled on the naming - the docs talk about this being a list of other frameworks that the project is compatible with..

2) project.json 框架问题 -

A) 我在哪里可以找到有关框架选项的最新或维护的列表或建议集?

A) Where can I find an up-to-date or maintained list or set of advice around the framework options?

B) 如果我对 import 的目的的理解是正确的,为什么它这么命名?如果不是,它究竟导入了什么?

B) If my understanding of the purpose of import is correct, why is it named so? If not, what exactly does it import?

C) 为什么每个 framework 属性都有一个 import 属性?如果要表明整个项目与另一个框架兼容,那似乎最好放在 project.json 的顶层,不是吗?

C) Why is there an import property for every framework property? If it's to indicate the whole project is compatible with another framework, that would seem to be best placed at the top level of project.json, no?

D) 我应该如何决定应该使用哪些 import 选项?dotnet new 只有 dnxcore50 - 要满足哪些包?这个人建议使用dotnet5.6dnxcore50portable-net45+win8!

D) How should I decide which import options should I use? dotnet new has just dnxcore50 - which packages is that to satisfy? This guy suggests dotnet5.6, dnxcore50 and portable-net45+win8!

最后,我正在构建类库、测试项目、控制台实用程序.所以..

Finally, I'm building class libraries, test projects, console utils. So..

3) 引用和包

A) 根据 dotnet new,我是否总是想要 Microsoft.NETCore.App?还有其他基线选项吗?选择指导?清单?

A) Do I always want Microsoft.NETCore.App as per dotnet new? Are there other baseline options? Guidance on choosing? A list?

B) 文档没有提到任何关于 type 选项(buildplatform).是否有关于这些的任何指导?

B) The docs don't mention anything about the type option (build, platform). Is there any guidance available on these?

C) 我的一些项目将使用 ASP.NET.在哪里可以找到要引用的正确软件包的最佳位置?NuGet 上似乎有一百万个版本和包.本教程只谈引用Microsoft.AspNetCore.Server.Kestrel - 唯一引用 ASP.NETty 的东西是 Microsoft.AspNetCore.Hosting.这是否意味着一个包是 ASP.NET 的大部分内容?

C) Some of my projects will use ASP.NET. Where's the best place to find the correct packages to reference? There seem to be a million versions and packages on NuGet. This tutorial just talks about referencing Microsoft.AspNetCore.Server.Kestrel - and the only ASP.NETty thing that refs is Microsoft.AspNetCore.Hosting. Does that mean that one package is most of ASP.NET?

推荐答案

您有很多问题.没有单独的文档,因为问题不是那么简单;)

You have many questions. There is no single documentation for it, because the questions are not that simple ones ;)

global.json

  • global.json 构建系统:global.json(作为 project.json)不指定构建系统(例如 msbuild csproj 文件除外).目前,只有 dotnet build 可用(在 VS 中使用时由 msbuild xproj 代理).这将更改为 msbuild,因为完整的工具处于预览/测试阶段,不会在 6 月底发布.它运行所有子文件夹并构建内容.它也是查找本地项目引用的根节点.
  • global.json sdk:这是用于构建的 sdk.新的 cli 还支持多个 sdk,我认为这仍然用于选择.
  • global.json build system: global.json (as project.json) do not specify a build system (other than e.g. msbuild csproj files). For now, only dotnet build is available (proxied by msbuild xproj when used in VS). This is going to change to msbuild because the complete tooling is in preview/beta and not going to release end of June. It runs over all the child folders and build the stuff. It is also the root node for looking up local project references.
  • global.json sdk: That is the sdk used for the build. The new cli also supports multiple sdks, and I think this is still used for selection.

project.json

  • project.json 框架列表:我建议你阅读 平台标准文档,您可以在那里找到当前框架名称的列表.本文档还将解决您(可能)遇到的许多其他问题.NuGet 项目文档 中提供了完整列表,但该列表再次被弃用,也没有那么有用.您的示例 netcore 引用用于 UWP(运行时也称为 .NET Core),而跨平台 .NET Core 使用 netcoreappNuGet 文档中完全没有.
  • project.json 导入:你在这里的目的是错误的.在 project.json 中,您指定要为其构建库的实现的目标框架(例如 netstandard1.6net451).import 语句用于您为目标框架指定的依赖项,基本上表示:如果引用的库中不存在 TFM(例如 netstandard1.6)(因为NuGet 是不久前构建的),我也接受这些导入一次(例如已弃用的 dotnet5.6dnxcore50).这是当前一个用于破坏 NuGet 并允许使用尚未移动到新 TFM 的库的实用程序.它没有说明您的项目,而是您接受使用哪些版本的依赖项.这需要针对每个目标框架制定单独的规范,因为每个目标框架对 NuGet 库实现的接受程度可能不同.
  • project.json 导入用法:好吧,使用您需要的并删除所有您不需要的.当您引用尚未迁移到新 TFM 的 NuGet 时,您将收到错误消息.dnxcoredotnet 是对 .NET Core 项目的节省赌注,因为它们已经在当前名称 netstandardnetcoreapp 之前使用过> 被创造出来.只是不要那么大胆地​​添加例如基于 net461/mscorlib 的 NuGet 实现到基于 netstandard/System.Runtime 的目标框架.这是行不通的,而且是一个常见的错误.
  • project.json list of framework: I recommend that you read the platform standard document and there you find a list of current framework monikers. This document will also resolve many other questions you (might) have. A complete list is in the NuGet project docs, but the list again is deprecated and not that useful either. You example netcore refers is used for UWP (which runtime is also called .NET Core) while the cross-platform .NET Core uses netcoreapp which is completely missing in NuGet documentation.
  • project.json import: you get here the purpose wrong. In project.json you specify the target frameworks for which implementations of your library are build (e.g. netstandard1.6 and net451). The import statement is used for dependencies you specify for the target framework and basically says: If the TFM (e.g. netstandard1.6) does not exist in a referenced library (because the NuGet was build a while ago), I also accept these imported once (e.g. the deprecated dotnet5.6 or dnxcore50). This is currently a utility to break NuGet and allow the usage of libraries which are not yet moved to the new TFMs. It does not say anything about your project but which versions of your dependencies you accept to use. That needs separate specification for each targeted frameworks because acceptance of NuGet library implementations might differ per targeted framework.
  • project.json import usage: well, use what you need and remove all you do not need. You will get errors when you refer NuGets which have not been migrated yet to the new TFM. dnxcore and dotnet are save bets on .NET Core projects because they have been used before the current monikers netstandard and netcoreapp have been coined. Just do not be that bold to add e.g. net461/mscorlib based NuGet implementations to a netstandard/System.Runtime based target framework. That does not work and is a common mistake.

依赖项

  • dotnet 新默认模板:是的,对于 ASP.NET 和控制台应用程序来说,这始终是正确的选择.然而,这只是一个简单的控制台应用程序(网络应用程序也是控制台应用程序).使用 Visual Studio 在 Linux 下创建新的 ASP.NET Core 项目或 yeoman 以进行高级模板化.dotnet new 不是一个完整的脚手架系统.新模板使用netcoreapp 目标框架和Microsoft.NETCore.App 元包来导入基本上所有可用的基类库.如果要创建库,请切换到 netstandard 目标框架并依赖于 NETStandard.Library.您仍然可以添加其他依赖项.对于 ASP.NET 核心,没有可用的直接元包.指导到此结束.有一个称为修剪的过程,您可以在其中删除这些元包并添加具体的依赖项.但目前还没有相应的工具.
  • project.json 构建/平台依赖项:build 依赖项本质上是工具,在构建期间不会发布.当你知道 npm 时,你就会知道这个方案是 devDependencies.platform 依赖项本质上是一种依赖项,它不与您的应用程序一起部署,而是作为 .NET Core SDK 的共享基础安装的一部分.您可以在便携式应用程序"一词下找到指南(即是平台)和自包含应用程序"(即没有).
  • project.json 元包/传递依赖:.NET Core 和 project.json 引入了元包的概念.Microsoft.NETCore.App 本质上是 .NET Core 命令行应用程序和类库的 NETStandard.Library 的基线依赖项.所有这些包都可以拥有自己的代码和其他包的可传递依赖项.这些你也可以使用.例如,Microsoft.NETCore.App 包引用了 NETStandard.Library,它再次引用了 System.Collections.Generic.因此,在引用 Microsoft.NETCore.App 的应用程序中,您可以使用通用集合.对于 ASP.NET Core,情况有所不同,因为按需付费的理念对性能非常关键.对于生产应用程序,您必须了解您添加的内容.首先,您必须使用像 VS 或 yeoman 这样的脚手架系统.Microsoft.AspNetCore.Server.Kestrel(例如纯文本)或 Microsoft.AspNetCore.Mvc(用于 web api)可传递地包含大多数其他关键的 ASP.NET Core 依赖项.
  • dotnet new default template: Yes, for ASP.NET and Console Apps that is always the right choice. However, this is just a simple console app (web apps are console apps as well). Use Visual Studio to create new ASP.NET Core projects or yeoman under Linux for advanced templating. dotnet new is not a full blown scaffolding system. The new template uses the netcoreapp target framework and the Microsoft.NETCore.App meta packages to import basically all available base class libraries. If you want to create a library, switch to netstandard target framework and depend on the NETStandard.Library. You can still add other dependencies. For ASP.NET core, no direct meta package is available. The guidance ends here. There is a process called trimming, where you remove these meta packages and add concrete dependencies instead. But there is not yet tooling for it.
  • project.json build/platform dependencies: build dependencies are essentially tools, which are not published during build. When you know npm you know this scheme as devDependencies. platform dependencies is essentially a dependency which is not deployed along with your app but as part of the shared base installation of the .NET Core SDK. You find guidance here under the term "portable application" (that is platform) and "self-contained application" (that is it without).
  • project.json meta packages / transitive dependencies: .NET Core and project.json introduce the concept of meta packages. Microsoft.NETCore.App is essentially the baseline dependency for a .NET Core command line app and NETStandard.Library for class libraries. All these packages can have code on their own and transitive dependencies for other packages. These you can also utilize then. As an example, the Microsoft.NETCore.App package refers NETStandard.Library which again refers System.Collections.Generic. So in your app which refers Microsoft.NETCore.App you can use generic collections. For ASP.NET Core the situation is different, because there the pay-as-you-go philosophy is very performance critical. For productive application you have to understand what you add. As a starter, you have to use scaffolding systems like VS or yeoman. The Microsoft.AspNetCore.Server.Kestrel (e.g. plain text) or Microsoft.AspNetCore.Mvc (for web api) transitively include most other critical ASP.NET Core dependencies.

免责声明:上面的大部分主题都与被视为预览"的工具有关.预览"的意思是测试版".即将发生重大变化(例如将构建系统从 project.json 切换回 msbuild,或再次完善 .NET 标准).

我希望这能回答您的大部分问题.我认为在一个问题中回答所有这些问题是一项挑战;)

I hope this answers most of your questions. I think answering all of them in one question is a challenge ;).

这篇关于.NET Core - 解决方案、框架、导入、运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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