关于 .NET CoreAbout .NET Core

.NET Core 具有以下特性:.NET Core has the following characteristics:

  • 跨平台: 可以在 Windows、macOS 和 Linux 操作系统上运行。Cross-platform: Runs on Windows, macOS and Linux operating systems.
  • 跨体系结构保持一致: 在多个体系结构(包括 x64、x86 和 ARM)上以相同的行为运行代码。Consistent across architectures: Runs your code with the same behavior on multiple architectures, including x64, x86, and ARM.
  • 命令行工具: 包括可用于本地开发和持续集成方案中的易于使用的命令行工具。Command-line tools: Includes easy-to-use command-line tools that can be used for local development and in continuous-integration scenarios.
  • 部署灵活: 可以包含在应用或已安装的并行(用户或系统范围安装)中。Flexible deployment: Can be included in your app or installed side-by-side (user-wide or system-wide installations). 可搭配 Docker 容器使用。Can be used with Docker containers.
  • 兼容性:.NET Core 通过 .NET Standard与 .NET Framework、Xamarin 和 Mono 兼容。Compatible: .NET Core is compatible with .NET Framework, Xamarin and Mono, via .NET Standard.
  • 开放源代码:.NET Core 平台是开放源代码,使用 MIT 和 Apache 2 许可证。Open source: The .NET Core platform is open source, using MIT and Apache 2 licenses. .NET Core 是一个 .NET Foundation 项目。.NET Core is a .NET Foundation project.
  • 由 Microsoft 支持:.NET Core 由 Microsoft 依据 .NET Core 支持提供支持。Supported by Microsoft: .NET Core is supported by Microsoft, per .NET Core Support.

语言Languages

可以使用 C#、Visual Basic 和 F# 语言编写适用于 .NET Core 的应用程序和库。C#, Visual Basic, and F# languages can be used to write applications and libraries for .NET Core. 这些语言已集成或可以集成到你最喜欢的文本编辑器和 IDE,包括 Visual StudioVisual Studio Code、Sublime Text 和 Vim。These languages are or can be integrated into your favorite text editors and IDEs, including Visual Studio, Visual Studio Code, Sublime Text and Vim. 这种集成部分由 OmniSharpIonide 项目的高手提供。This integration is provided, in part, by the good folks from the OmniSharp and Ionide projects.

APIAPIs

.NET Core 公开了多种方案的 API,以下介绍了几种:.NET Core exposes APIs for many scenarios, a few of which follow:

.NET Core 通过实现 .NET Standard 规范提供 .NET Framework 和 Mono API 的兼容性。.NET Core provides compatibility with .NET Framework and Mono APIs by implementing the .NET Standard specification.

框架Frameworks

在 .NET Core 之上建立了多个框架:Multiple frameworks have been built on top of .NET Core:

撰写Composition

.NET Core 包括以下部分:.NET Core is composed of the following parts:

  • .NET Core 运行时:提供类型系统、程序集加载、垃圾回收器、本机互操作和其他基本服务。The .NET Core runtime, which provides a type system, assembly loading, a garbage collector, native interop and other basic services. .NET Core 框架库提供基元数据类型、应用编写类型和基本实用程序。.NET Core framework libraries provide primitive data types, app composition types and fundamental utilities.
  • ASP.NET 运行时:提供框架以生成基于新式云的 Internet 连接的应用程序,例如 Web 应用、IoT 应用以及移动后端。The ASP.NET runtime, which provides a framework for building modern cloud based internet connected applications, such as web apps, IoT apps and mobile backends.
  • .NET Core CLI 工具和语言编译器(RoslynF#):提供 .NET Core 开发人员体验。The .NET Core CLI tools and language compilers (Roslyn and F#) that enable the .NET Core developer experience.
  • dotnet 工具:用于启动 .NET Core 应用和 CLI 工具。The dotnet tool, which is used to launch .NET Core apps and CLI tools. 它选择运行时并托管运行时,提供程序集加载策略并启动应用和工具。It selects the runtime and hosts the runtime, provides an assembly loading policy and launches apps and tools.

这些组件采用以下方式分布:These components are distributed in the following ways:

  • .NET Core 运行时 -- 包括 .NET Core 运行时和框架库。.NET Core Runtime -- includes the .NET Core runtime and framework libraries.
  • ASP.NET Core 运行时 -- 包括 ASP.NET Core 和 .NET Core 运行时以及框架库。ASP.NET Core Runtime -- includes ASP.NET Core and .NET Core runtime and framework libraries.
  • .NET Core SDK -- 包括 .NET CLI 工具、ASP.NET Core 运行时以及 .NET Core 运行时和框架。.NET Core SDK -- includes the .NET CLI Tools, ASP.NET Core runtime, and .NET Core runtime and framework.

开源Open source

.NET Core 属于开放源(MIT 许可证),由 Microsoft 于 2014 年提供给 .NET Foundation.NET Core is open source (MIT license) and was contributed to the .NET Foundation by Microsoft in 2014. 现在它是最活跃的 .NET Foundation 项目之一。It is now one of the most active .NET Foundation projects. 可由个人和企业自由采用,包括用于个人、学术或商业目的。It can be freely adopted by individuals and companies, including for personal, academic or commercial purposes. 许多公司已使用 .NET Core 作为应用、工具、新平台和托管服务的一部分。Multiple companies use .NET Core as part of apps, tools, new platforms and hosting services. 其中某些公司对 GitHub 上的 .NET Core 做出了巨大贡献,并作为 .NET Foundation Technical Steering Group(.NET Foundation 技术控制组)的成员,指导产品方向。Some of these companies make significant contributions to .NET Core on GitHub and provide guidance on the product direction as part of the .NET Foundation Technical Steering Group.

针对适应性而设计Designed for adaptability

与其他 .NET 产品相比,生成的 .NET Core 与它们十分类似,但具有唯一性。.NET Core has been built as a very similar but unique product relative to other .NET products. 其目的是能够广泛适应新的平台和工作负载。It has been designed to enable broad adaptability to new platforms and workloads. 它提供多个 OS 和 CPU 端口,并可以移植到更多端口。It has several OS and CPU ports available and may be ported to many more.

该产品分为几个部分,使各个部件能够在不同的时间适应新的平台。The product is broken into several pieces, enabling the various parts to be adapted to new platforms at different times. 必须将运行时和特定于平台的基础库作为一个单元进行移植。The runtime and platform-specific foundational libraries must be ported as a unit. 与平台无关的库应在所有平台上按照构建的原样运行。Platform-agnostic libraries should work as-is on all platforms, by construction. 对于通过减少特定于平台的实现以提高开发人员效率方面,项目存在偏差,但每当可以以此方式全部或部分实现算法或 API 时,都应首选与平台无关的 C# 代码。There is a project bias to reducing platform-specific implementations to increase developer efficiency, preferring platform-neutral C# code whenever an algorithm or API can be implemented in-full or in-part that way.

人们经常会问,为支持多个操作系统应如何实现 .NET Core。People commonly ask how .NET Core is implemented in order to support multiple operating systems. 他们还会问是否存在单独的实现,或是否使用 conditional compilation(条件编译)。They typically ask if there are separate implementations or if conditional compilation is used. 这两者都在用,但强烈偏向条件编译。It's both, with a strong bias towards conditional compilation.

可以在下面的图表看出大多数 CoreFX 都是与平台无关的代码,该代码可在所有平台共享。You can see in the following chart that the vast majority of CoreFX is platform-neutral code that is shared across all platforms. 不限平台的代码可实现为在所有平台上使用的单个可移植程序集。Platform-neutral code can be implemented as a single portable assembly that is used on all platforms.

CoreFX:每个平台的代码行数

Windows 和 Unix 实现大小相似。Windows and Unix implementations are similar in size. Windows 具有较大的实现,因为 CoreFX 实现了某些仅适用于 Windows 的功能,如 Microsoft.Win32.Registry,但尚未实现多个仅适用于 Unix 的概念。Windows has a larger implementation since CoreFX implements some Windows-only features, such as Microsoft.Win32.Registry but does not yet implement many Unix-only concepts. 你将发现大多数 Linux 和 macOS 实现都是在 Unix 实现中实现的,而特定于 Linux 和 macOS 的实现大小大致相同。You will also see that the majority of the Linux and macOS implementations are shared across a Unix implementation, while the Linux- and macOS-specific implementations are roughly similar in size.

.NET Core 中混合存在特定于平台和与平台无关的库。There are a mix of platform-specific and platform-neutral libraries in .NET Core. 可以查看几个示例中的模式:You can see the pattern in a few examples:

与其他 .NET 实现比较Comparisons to other .NET implementations

将 .NET Core 与现有的 .NET 实现进行比较,这可能是了解其大小和形状最简单的方法。It is perhaps easiest to understand the size and shape of .NET Core by comparing it to existing .NET implementations.

与 .NET Framework 比较Comparison with .NET Framework

.NET 由 Microsoft 于 2000 年首次发布,而后发展至今。.NET was first announced by Microsoft in 2000 and then evolved from there. 近 20 年以来,.NET Framework 一直是 Microsoft 出品的主要 .NET 实现。The .NET Framework has been the primary .NET implementation produced by Microsoft during that nearly two decade period.

.NET Core 和 .NET Framework 的主要差异在于:The major differences between .NET Core and the .NET Framework:

  • 应用模型 -- .NET Core 不支持所有 .NET Framework 应用模型。App-models -- .NET Core does not support all the .NET Framework app-models. 具体而言,它不支持 ASP.NET Web 窗体和 ASP.NET MVC,但支持 ASP.NET Core MVC。In particular, it doesn't support ASP.NET Web Forms and ASP.NET MVC, but it supports ASP.NET Core MVC. 已宣布 .NET Core 3 将支持 WPF 和 Windows 窗体It was announced that .NET Core 3 will support WPF and Windows Forms.
  • API -- .NET Core 包含 .NET Framework 基类库的一个大型子集,但具有不同的组成要素(程序集名称不同;类型上公开的成员在关键用例中不同)。APIs -- .NET Core contains a large subset of .NET Framework Base Class Library, with a different factoring (assembly names are different; members exposed on types differ in key cases). 这些差异需要在某些情况下更改 .NET Core 的端口源(请参阅 microsoft/dotnet-apiport)。These differences require changes to port source to .NET Core in some cases (see microsoft/dotnet-apiport). .NET Core 实施 .NET Standard API 规范。.NET Core implements the .NET Standard API specification.
  • 子系统 -- .NET Core 实现 .NET Framework 中子系统的子级,目的是实现更简单的实现和编程模型。Subsystems -- .NET Core implements a subset of the subsystems in the .NET Framework, with the goal of a simpler implementation and programming model. 例如,不支持代码访问安全性 (CAS),但支持反射。For example, Code Access Security (CAS) is not supported, while reflection is supported.
  • 平台 -- .NET Framework 支持 Windows 和 Windows Server,而 NET Core 还支持 macOS 和 Linux。Platforms -- The .NET Framework supports Windows and Windows Server while .NET Core also supports macOS and Linux.
  • 开放源 -- .NET Core 属于开放源,而 .NET Framework 的只读子集属于开放源。Open Source -- .NET Core is open source, while a read-only subset of the .NET Framework is open source.

虽然 .NET Core 是唯一的且与 .NET Framework 和其他 .NET 实现大不相同,但使用源或二进制共享技术在这些实施之间分享代码仍很简单。While .NET Core is unique and has significant differences to the .NET Framework and other .NET implementations, it is straightforward to share code between these implementations, using either source or binary sharing techniques.

由于 .NET Core 支持并行安装及其运行时完全独立于 .NET Framework,它可以安装在装有.NET Framework 的计算机上,不会出现任何问题。Because .NET Core supports side-by-side installation and its runtime is completely independent of the .NET Framework, it can be installed on machines with .NET Framework installed without any issues.

与 Mono 比较Comparison with Mono

Mono 是原始的跨平台和 开放源 .NET 实现,于 2004 年首次发布。Mono is the original cross-platform and open source .NET implementation, first shipping in 2004. 可以把它看作是 .NET Framework 的社区克隆。It can be thought of as a community clone of the .NET Framework. Mono 项目团队依赖于 Microsoft 发布的开放 .NET 标准(尤其是 ECMA 335),以便实现兼容性。The Mono project team relied on the open .NET standards (notably ECMA 335) published by Microsoft in order to provide a compatible implementation.

.NET Core 和 Mono 的主要差异在于:The major differences between .NET Core and Mono:

  • 应用模型 -- Mono 通过 Xamarin 产品支持 .NET Framework 应用模型(例如,Windows Forms)和其他应用模型(例如,Xamarin.iOS)的子集。App-models -- Mono supports a subset of the .NET Framework app-models (for example, Windows Forms) and some additional ones (for example, Xamarin.iOS) through the Xamarin product. 而 .NET Core 不支持这些内容。.NET Core doesn't support these.
  • API -- Mono 使用相同程序集名称和组成要素支持 .NET Framework API 的 大型子集APIs -- Mono supports a large subset of the .NET Framework APIs, using the same assembly names and factoring.
  • 平台 -- Mono 支持很多平台和 CPU。Platforms -- Mono supports many platforms and CPUs.
  • 开放源 -- Mono 和 .NET Core 两者都使用 MIT 许可证,且都属于 .NET Foundation 项目。Open Source -- Mono and .NET Core both use the MIT license and are .NET Foundation projects.
  • 焦点 -- 最近几年,Mono 的主要焦点是移动平台,而 .NET Core 的焦点是云和桌面工作负载。Focus -- The primary focus of Mono in recent years is mobile platforms, while .NET Core is focused on cloud and desktop workloads.