.NET 简介Introduction to .NET

.NET 是一种用于构建多种应用的免费开源开发平台,例如:.NET is a free, open-source development platform for building many kinds of apps, such as:

使用类库在不同应用和应用类型中共享功能。Share functionality among different apps and app types by using class libraries.

使用 .NET 时,无论你正在构建哪种类型的应用,代码和项目文件看起来都一样。With .NET, your code and project files look and feel the same no matter which type of app you're building. 可以访问每个应用的相同运行时、API 和语言功能。You have access to the same runtime, API, and language capabilities with each app.

跨平台Cross platform

可以为许多操作系统创建 .NET 应用,包括:You can create .NET apps for many operating systems, including:

  • WindowsWindows
  • macOSmacOS
  • LinuxLinux
  • AndroidAndroid
  • iOSiOS
  • tvOStvOS
  • watchOSwatchOS

支持的处理器体系结构包括:Supported processor architectures include:

  • X64x64
  • x86x86
  • ARM32ARM32
  • ARM64ARM64

通过 .NET,可以使用特定于平台的功能,如操作系统 API。.NET lets you use platform-specific capabilities, such as operating system APIs. 例如 Windows 上的 Windows 窗体和 WPF,以及从 Xamarin 到每个移动平台的原生绑定。Examples are Windows Forms and WPF on Windows and the native bindings to each mobile platform from Xamarin.

有关详细信息,请参阅支持的 OS 生命周期策略.NET RID 目录For more information, see Supported OS lifecycle policy and .NET RID Catalog.

开源Open source

.NET 是开放源代码,使用 MIT 和 Apache 2 许可证.NET is open source, using MIT and Apache 2 licenses. .NET 是 .NET Foundation 的项目。.NET is a project of the .NET Foundation.

有关详细信息,请参阅 GitHub.com 上的项目存储库列表For more information, see the list of project repositories on GitHub.com.

支持Support

Microsoft 支持在 Windows、macOS 和 Linux 上使用 .NET。.NET is supported by Microsoft on Windows, macOS, and Linux. 它会定期更新以保证安全和质量(每月的第二个星期二)。It's updated regularly for security and quality, on the second Tuesday of each month.

Microsoft 的 .NET 二进制发行版在 Azure 中的 Microsoft 维护服务器上进行生成和测试,并遵循 Microsoft 的工程和安全实践。.NET binary distributions from Microsoft are built and tested on Microsoft-maintained servers in Azure and follow Microsoft engineering and security practices.

Red Hat 支持在 Red Hat Enterprise Linux (RHEL) 上使用 .NETRed Hat supports .NET on Red Hat Enterprise Linux (RHEL). Red Hat 和 Microsoft 开展协作,共同确保 .NET Core 能够在 RHEL 上正常运行。Red Hat and Microsoft collaborate to ensure that .NET Core works well on RHEL.

Tizen 支持在 Tizen 平台上使用 .NETTizen supports .NET on Tizen platforms.

有关详细信息,请参阅 .NET Core 和 .NET 5 的版本和支持For more information, see Releases and support for .NET Core and .NET 5.

工具与工作效率Tools and productivity

.NET 为用户提供了各种语言、集成开发环境 (IDE) 和其他工具的选择。.NET gives you a choice of languages, integrated development environments (IDEs), and other tools.

编程语言Programming languages

.NET 支持三种编程语言:.NET supports three programming languages:

  • C#C#

    C#(读作“See Sharp”)是一种新式编程语言,不仅面向对象,还类型安全。C# (pronounced "See Sharp") is a modern, object-oriented, and type-safe programming language. C# 源于 C 语言系列,C、C++、Java 和 JavaScript 程序员很快就可以上手使用。C# has its roots in the C family of languages and will be immediately familiar to C, C++, Java, and JavaScript programmers.

  • F#F#

    F# 语言支持函数式、命令式、面向对象的编程模式。The F# language supports functional, object-oriented, and imperative programming models.

  • Visual BasicVisual Basic

    在 .NET 语言中,Visual Basic 的语法最接近于人类的普通用语,因此更易于学习。Among the .NET languages, the syntax of Visual Basic is the closest to ordinary human language, which can make it easier to learn. 不同于 C# 和 F#(Microsoft 正在积极为 C# 和 F# 开发新功能),Visual Basic 语言是稳定的。Unlike C# and F#, for which Microsoft is actively developing new features, the Visual Basic language is stable. Visual Basic 不受 Web 应用支持,但受 Web API 支持。Visual Basic isn't supported for web apps, but it is supported for web APIs.

下面是 .NET 语言支持的一些功能:Here are some of the capabilities that .NET languages support:

IDEIDEs

.NET 的集成开发环境包括:The integrated development environments for .NET include:

  • Visual StudioVisual Studio

    仅在 Windows 上运行。Runs on Windows only. 具有广泛的内置功能,设计为可以与 .NET 一起使用。Has extensive built-in functionality designed to work with .NET. 社区版对学生、开放源代码贡献者和个人免费。The Community edition is free for students, open-source contributors, and individuals.

  • Visual Studio CodeVisual Studio Code

    在 Windows、macOS 和 Linux 上运行。Runs on Windows, macOS, and Linux. 免费且开源。Free and open source. 扩展可用于使用 .NET 语言。Extensions are available for working with .NET languages.

  • Visual Studio for MacVisual Studio for Mac

    仅在 macOS 上运行。Runs on macOS only. 用于开发适用于 iOS、Android 和 Web 的 .NET 应用和游戏。For developing .NET apps and games for iOS, Android, and web.

  • GitHub CodespacesGitHub Codespaces

    联机 Visual Studio Code 环境,当前为 beta 版本。An online Visual Studio Code environment, currently in beta.

SDK 和运行时SDK and runtimes

.NET SDK 是一组用于开发和运行 .NET 应用程序的库和工具。The .NET SDK is a set of libraries and tools for developing and running .NET applications.

下载 .NET 时,可以选择 SDK 或 运行时,例如 .NET 运行时或 ASP.NET Core 运行时。When you download .NET, you can choose the SDK or a runtime, such as the .NET runtime or the ASP.NET Core runtime. 在要准备运行 .NET 应用的计算机上安装运行时。Install a runtime on a machine that you want to prepare for running .NET apps. 在要用于开发的计算机上安装 SDK。Install the SDK on a machine that you want to use for development. 下载 SDK 时,将自动获取运行时。When you download the SDK, you automatically get the runtimes with it.

SDK 下载包括以下组件:The SDK download includes the following components:

  • .NET CLIThe .NET CLI. 可用于本地开发和持续集成脚本的命令行工具。Command-line tools that you can use for local development and continuous integration scripts.
  • dotnet 驱动程序The dotnet driver. 用于运行依赖于框架的应用的 CLI 命令。A CLI command that runs framework-dependent apps.
  • RoslynF# 编程语言编译器。The Roslyn and F# programming language compilers.
  • MSBuild 生成引擎。The MSBuild build engine.
  • .NET 运行时The .NET runtime. 提供类型系统、程序集加载、垃圾回收器、本机互操作和其他基本服务。Provides a type system, assembly loading, a garbage collector, native interop, and other basic services.
  • 运行时库Runtime libraries. 提供基元数据类型和基本实用程序。Provides primitive data types and fundamental utilities.
  • ASP.NET Core 运行时。The ASP.NET Core runtime. 为连接 Internet 的应用(如 Web 应用、IoT 应用和移动后端)提供基本服务。Provides basic services for internet-connected apps, such as web apps, IoT apps, and mobile backends.
  • 桌面运行时。The desktop runtime. 为 Windows 桌面应用(包括 Windows 窗体和 WPF)提供基本服务。Provides basic services for Windows desktop apps, including Windows Forms and WPF.

运行时下载包括以下组件:The runtime download includes the following components:

  • (可选)桌面或 ASP.NET Core 运行时。Optionally, the desktop or ASP.NET Core runtime.
  • .NET 运行时The .NET runtime. 提供类型系统、程序集加载、垃圾回收器、本机互操作和其他基本服务。Provides a type system, assembly loading, a garbage collector, native interop, and other basic services.
  • 运行时库Runtime libraries. 提供基元数据类型和基本实用程序。Provides primitive data types and fundamental utilities.
  • dotnet 驱动程序The dotnet driver. 用于运行依赖于框架的应用的 CLI 命令。A CLI command that runs framework-dependent apps.

有关详细信息,请参阅以下资源:For more information, see the following resources:

项目系统和 MSBuildProject system and MSBuild

.NET 应用是使用 MSBuild 从源代码中生成的。A .NET app is built from source code by using MSBuild. 项目文件(.csproj、.fsproj 或 .vbproj)指定目标和负责编译、打包和发布代码的关联任务A project file (.csproj, .fsproj, or .vbproj) specifies targets and associated tasks that are responsible for compiling, packing, and publishing code. 有引用目标和任务的标准集合的 SDK 标识符。There are SDK identifiers that refer to standard collections of targets and tasks. 使用这些标识符有助于使项目文件较小且易于使用。The use of these identifiers helps keep project files small and easy to work with. 例如,下面是控制台应用的一个项目文件:For example, here is a project file for a console app:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>
</Project>

下面是 Web 应用的一个项目文件:And here's one for a web app:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>
</Project>

在这些示例中,Project 元素的 Sdk 属性指定一组 MSBuild 目标和生成项目的任务。In these examples, the Sdk attribute of the Project element specifies a set of MSBuild targets and tasks that build the project. TargetFramework 元素指定应用所依赖的 .NET 版本。The TargetFramework element specifies the .NET version that the app depends on. 可以编辑项目文件以添加特定于项目的其他目标和任务。You can edit the project file to add additional targets and tasks specific to the project.

有关详细信息,请参阅 .NET 项目 SDK 概述目标框架For more information, see .NET project SDK overview and Target frameworks.

CI/CDCI/CD

MSBuild 和 .NET CLI 可与各种连续集成工具和环境一起使用,例如:MSBuild and the .NET CLI can be used with various continuous integration tools and environments, such as:

有关详细信息,请参阅在持续集成 (CI) 中使用 .NET SDK 和工具For more information, see Using .NET SDK and tools in Continuous Integration (CI)

NuGetNuGet

NuGet 是为 .NET 设计的开源包管理器。NuGet is an open-source package manager designed for .NET. NuGet 包是具有 .nupkg 扩展的 .zip 文件,此扩展包含编译代码 (DLL)、与该代码相关的其他文件以及描述性清单(包含包版本号等信息)。A NuGet package is a .zip file with the .nupkg extension that contains compiled code (DLLs), other files related to that code, and a descriptive manifest that includes information like the package's version number. 使用代码的开发人员共享创建包,并将其发布到 nuget.org 或专用主机。Developers with code to share create packages and publish them to nuget.org or a private host. 希望使用共享代码的开发人员将包添加到其项目中,然后可以在项目代码中调用包公开的 API。Developers who want to use shared code add a package to their project and can then call the API exposed by the package in their project code.

有关详细信息,请参阅 NuGet 文档For more information, see NuGet documentation.

.NET Interactive.NET Interactive

.NET Interactive 是一组 CLI 工具和 API,使用户能够跨 Web、markdown 和笔记本创建交互式体验。.NET Interactive is a group of CLI tools and APIs that enable users to create interactive experiences across the web, markdown, and notebooks.

有关详细信息,请参阅以下资源:For more information, see the following resources:

执行模型Execution models

.NET 应用在称为“公共语言运行时 (CLR)”的运行时环境中运行托管代码.NET apps run managed code in a runtime environment known as the Common Language Runtime (CLR).

CLRCLR

.NET CLR 是包含 Windows、macOS 和 Linux 支持的跨平台运行时。The .NET CLR is a cross-platform runtime that includes support for Windows, macOS, and Linux. CLR 处理内存分配和管理。The CLR handles memory allocation and management. CLR 也是一个虚拟机,不仅可执行应用,还可使用实时 JIT 编译器生成和编译代码。The CLR is also a virtual machine that not only executes apps but also generates and compiles code using a just-in-time (JIT) compiler.

有关详细信息,请参阅公共语言运行时 (CLR) 概述For more information, see Common Language Runtime (CLR) overview.

JIT 编译器和 ILJIT compiler and IL

C# 等较高级的 .NET 语言编译为称为中间语言 (IL) 的硬件无关性指令集。Higher-level .NET languages, such as C#, compile down to a hardware-agnostic instruction set, which is called Intermediate Language (IL). 应用运行时,JIT 编译器将 IL 转换为处理器可理解的计算机代码。When an app runs, the JIT compiler translates IL to machine code that the processor understands. JIT 编译发生在要运行代码的同一台计算机上。JIT compilation happens on the same machine that the code is going to run on.

由于 JIT 编译在应用程序的执行过程中发生,因此编译时间是运行时的一部分。Since JIT compilation occurs during execution of the application, the compilation time is part of the run time. 因此,JIT 编译器需要平衡优化代码所花费的时间与生成代码时可节约的时间。Therefore, JIT compilers have to balance time spent optimizing code against the savings that the resulting code can produce. 但 JIT 编译器知道实际硬件,这样开发人员就无需为不同平台提供不同的实现。But a JIT compiler knows the actual hardware and can free developers from having to ship different implementations for different platforms.

.NET JIT 编译器可以执行分层编译,这意味着它可以在运行时重新编译各个方法。The .NET JIT compiler can do tiered compilation, which means it can recompile individual methods at run time. 通过此功能,它可以快速编译,同时仍然能够为常用方法生成高度优化的代码版本。This feature lets it compile quickly while still being able to produce a highly tuned version of the code for frequently used methods.

有关详细信息,请参阅托管执行过程分层编译For more information, see Managed execution process and Tiered compilation.

AOT 编译器AOT compiler

大多数 .NET 工作负载的默认体验是 JIT 编译器,但 .NET 提供两种形式的预先 (AOT) 编译:The default experience for most .NET workloads is the JIT compiler, but .NET offers two forms of ahead-of-time (AOT) compilation:

  • 某些场景需要 100% AOT 编译。Some scenarios require 100% AOT compilation. 例如 iOSAn example is iOS.
  • 在其他情况下,应用的大多数代码都是 AOT 编译的,但有些代码是 JIT 编译的。In other scenarios, most of an app's code is AOT-compiled but some is JIT-compiled. 某些代码模式不适用于 AOT(如泛型)。Some code patterns aren't friendly to AOT (like generics). 这种形式的 AOT 编译的示例为准备运行发布选项。An example of this form of AOT compilation is the ready-to-run publish option. 这种形式的 AOT 具有 AOT 的优点并且没有 AOT 的缺点。This form of AOT offers the benefits of AOT without its drawbacks.

自动内存管理Automatic memory management

垃圾回收器 (GC) 管理应用程序的内存分配和释放。The garbage collector (GC) manages the allocation and release of memory for applications. 每当代码新建对象时,CLR 都会从托管堆为对象分配内存。Each time your code creates a new object, the CLR allocates memory for the object from the managed heap. 只要托管堆中有地址空间,运行时就会继续为新对象分配空间。As long as address space is available in the managed heap, the runtime continues to allocate space for new objects. 没有足够的可用地址空间时,GC 将检查托管堆中应用程序不再使用的对象。When not enough free address space remains, the GC checks for objects in the managed heap that are no longer being used by the application. 然后回收该内存。It then reclaims that memory.

GC 是一种有助于确保内存安全的 CLR 服务。The GC is one of the CLR services that help ensure memory safety. 如果某个程序仅访问分配的内存,则该程序就是内存安全的。A program is memory safe if it accesses only allocated memory. 例如,运行时可确保应用不会访问超过数组边界的未分配内存。For instance, the runtime ensures that an app doesn't access unallocated memory beyond the bounds of an array.

有关详细信息,请参阅自动内存管理垃圾回收的基础知识For more information, see Automatic memory management and Fundamentals of garbage collection.

处理未托管的资源Working with unmanaged resources

有时,代码需要引用 非托管资源Sometimes code needs to reference unmanaged resources. 未托管的资源是指不由 .NET 运行时自动维护的资源。Unmanaged resources are resources that aren't automatically maintained by the .NET runtime. 例如,文件句柄就是未托管的资源。For example, a file handle is an unmanaged resource. FileStream 对象是一个托管对象,但它引用未托管的文件句柄。A FileStream object is a managed object, but it references a file handle, which is unmanaged. 用完 FileStream 之后,需要显式释放文件句柄。When you're done using the FileStream, you need to explicitly release the file handle.

在 .NET 中,引用未托管资源的对象会实现 IDisposable 接口。In .NET, objects that reference unmanaged resources implement the IDisposable interface. 用完对象后,需调用此对象的 Dispose() 方法,该方法会释放所有托管资源。When you're done using the object, you call the object's Dispose() method, which is responsible for releasing any unmanaged resources. .NET 语言提供一种方便的 using 语句(C#F#VB),确保调用 Dispose 方法。The .NET languages provide a convenient using statement (C#, F#, VB) that ensures the Dispose method is called.

有关详细信息,请参阅清理非托管资源For more information, see Cleaning up unmanaged resources.

部署模型Deployment models

可以在两种不同模式下发布 .NET 应用:.NET apps can be published in two different modes:

  • 将应用作为独立应用,生成的可执行文件将包含 .NET 运行时,以及该应用程序及其依赖项。Publishing an app as self-contained produces an executable file that includes the .NET runtime and libraries, and the application and its dependencies. 应用程序的用户可以在未安装 .NET 运行时的计算机上运行该应用程序。Users of the application can run it on a machine that doesn't have the .NET runtime installed. 独立应用是特定于平台的,可以使用 AOT 编译形式进行选择性发布。Self-contained apps are platform-specific, and they can optionally be published using a form of AOT compilation.

  • 将应用作为依赖于框架的应用发布会生成一个可执行文件和多个二进制文件(.dll 文件),其中仅包括应用程序本身及其依赖项 。Publishing an app as framework-dependent produces an executable file and binary files (.dll files) that include only the application itself and its dependencies. 应用程序的用户必须单独安装 .NET 运行时Users of the application have to separately install the .NET runtime. 可执行文件是特定于平台的,但依赖于框架的应用程序的 .dll 文件是跨平台的。The executable file is platform-specific, but the .dll files of framework-dependent applications are cross-platform.

    可以并行安装多个版本的运行时,以运行针对不同运行时版本的依赖于框架的应用。You can install multiple versions of the runtime side by side to run framework-dependent apps that target different versions of the runtime. 有关详细信息,请参阅目标框架For more information, see Target frameworks.

可执行文件是针对特定目标平台生成的,你可以通过运行时标识符 (RID) 指定。Executables are produced for specific target platforms, which you specify with a runtime identifier (RID).

有关详细信息,请参阅 .NET 应用程序发布概述.NET 和 Docker 简介For more information, see .NET application publishing overview and Introduction to .NET and Docker.

运行时库Runtime libraries

.NET 具有一组广泛的标准类库,称为运行时库框架库基类库 (BCL).NET has an expansive standard set of class libraries, known as runtime libraries, framework libraries, or the base class library (BCL). 这些库为许多常规用途类型和特定于工作负载的类型和实用工具功能提供实现。These libraries provide implementations for many general-purpose and workload-specific types and utility functionality.

下面是在 .NET 运行时库中定义的一些类型示例:Here are some examples of types defined in the .NET runtime libraries:

有关详细信息,请参阅运行时库概述For more information, see the Runtime libraries overview. 库的源代码位于 GitHub dotnet/运行时存储库中。The source code for the libraries is in the GitHub dotnet/runtime repository.

运行时库的扩展Extensions to the runtime libraries

某些常用应用程序功能的库没有包含在运行时库中,但在 NuGet 包中提供,如下所示:Libraries for some commonly used application functionality aren't included in the runtime libraries but are made available in NuGet packages, such as the following:

NuGet 包NuGet package 文档Documentation
Microsoft.Extensions.HostingMicrosoft.Extensions.Hosting 应用程序生存期管理(通用主机)Application lifetime management (Generic Host)
Microsoft.Extensions.DependencyInjectionMicrosoft.Extensions.DependencyInjection 依赖关系注入 (DI)Dependency injection (DI)
Microsoft.Extensions.ConfigurationMicrosoft.Extensions.Configuration 配置Configuration
Microsoft.Extensions.LoggingMicrosoft.Extensions.Logging LoggingLogging
Microsoft.Extensions.OptionsMicrosoft.Extensions.Options 选项模式Options pattern

有关详细信息,请参阅 GitHub 上的 dotnet/extensions 存储库For more information, see the dotnet/extensions repository on GitHub.

数据访问Data access

.NET 提供了对象/关系映射器 (ORM) 和一种在代码中编写 SQL 查询的方法。.NET provides an Object/Relational Mapper (ORM) and a way to write SQL queries in code.

Entity Framework CoreEntity Framework Core

Entity Framework (EF) Core 是一种可用作 ORM 的开源和跨平台的数据访问技术。Entity Framework (EF) Core is an open source and cross-platform data-access technology that can serve as an ORM. 借助 EF Core,可以通过引用代码中的 .NET 对象来处理数据库。EF Core lets you work with a database by referring to .NET objects in code. 它减少了需要编写和测试的数据访问代码的数量。It reduces the amount of data-access code you would otherwise need to write and test. EF Core 支持许多数据库引擎。EF Core supports many database engines.

有关详细信息,可参阅 Entity Framework Core数据库提供程序For more information, see Entity Framework Core and Database Providers.

LINQLINQ

通过语言集成查询 (LINQ),可以编写用于数据操作的声明性代码。Language-integrated query (LINQ) lets you write declarative code for operating on data. 数据可采用多种形式(例如,内存中对象、SQL 数据库或 XML 文档),但针对每个数据源编写的 LINQ 代码往往没有差别。The data can be in many forms (such as in-memory objects, a SQL database, or an XML document), but the LINQ code you write typically doesn't differ by data source.

有关详细信息,请参阅 LINQ(语言集成查询)概述For more information, see LINQ (Language Integrated Query) overview.

.NET 术语.NET terminology

了解一些术语在一段时期内的用法变化有利于理解 .NET 文档。To understand .NET documentation, it can help to know how the usage of some terms has changed over time.

.NET Core 和 .NET 5.NET Core and .NET 5

在 2002 年,Microsoft 发布了 .NET Framework,这是用于创建 Windows 应用的开发平台。In 2002, Microsoft released .NET Framework, a development platform for creating Windows apps. 目前 .NET Framework 的版本为 4.8,并且仍由 Microsoft 支持Today .NET Framework is at version 4.8 and is still supported by Microsoft.

2014 年,Microsoft 开始编写 .NET Framework 的跨平台开源后续产品。In 2014, Microsoft began writing a cross-platform, open-source successor to .NET Framework. .NET 的这个新实现被命名为 .NET Core,直到发展到版本 3.1。This new implementation of .NET was named .NET Core until it reached version 3.1. .NET Core 3.1 之后的下一个版本是 .NET 5.0,当前处于预览状态。The next version after .NET Core 3.1 is .NET 5.0, which is currently in preview. 版本号 4 被跳过,以避免 .NET 的此实现和 .NET Framework 4.8 混淆。Version number 4 was skipped to avoid confusion between this implementation of .NET and .NET Framework 4.8. 删除名称“Core”以表明这是现在 .NET 的主要实现。The name "Core" was dropped to make clear that this is now the main implementation of .NET.

本文是关于 .NET 5 的,但 .NET 5 文档的许多内容仍然引用“.NET Core”或“.NET Framework”。This article is about .NET 5, but much of the documentation for .NET 5 still has references to ".NET Core" or ".NET Framework". 此外,“Core”在名称 ASP.NET CoreEntity Framework Core 中保留。In addition, "Core" remains in the names ASP.NET Core and Entity Framework Core.

该文档还引用 .NET Standard。The documentation also refers to .NET Standard. .NET Standard 是一种 API 规范,可让你为 .NET 的多个实现开发类库。.NET Standard is an API specification that lets you develop class libraries for multiple implementations of .NET.

有关详细信息,请参阅 .NET 体系结构组件For more information, see .NET architectural components.

重载术语Overloaded terms

.NET 的一些术语可能会令人困惑,因为同一个术语在不同的上下文中的用法不同。Some of the terminology for .NET can be confusing because the same word is used in different ways in different contexts. 下面是一些较明显的例子:Here are a few of the more prominent instances:

  • 运行时runtime

    上下文Context “运行时”含义"runtime" meaning
    公共语言运行时 (CLR)Common Language Runtime (CLR) 用于托管程序的执行环境。The execution environment for a managed program. OS 属于运行时环境,但不属于 .NET 运行时。The OS is part of the runtime environment but isn't part of the .NET runtime.
    .Net 下载页上的 .NET 运行时.NET runtime on the .NET download page CLR运行时库,它们一起提供了对运行依赖于框架的应用的支持。The CLR and runtime libraries, which together provide support for running framework-dependent apps. 此页还提供 ASP.NET Core 服务器应用和 Windows 桌面应用的运行时选项。The page also offers runtime choices for ASP.NET Core server apps and Windows desktop apps.
    运行时标识符 (RID)Runtime Identifier (RID) 运行 .NET 应用的 OS 平台和 CPU 体系结构。The OS platform and CPU architecture that a .NET app runs on. 例如:Windows x64、Linux x64。For example: Windows x64, Linux x64.
  • 框架framework

    上下文Context “框架”含义"framework" meaning
    .NET framework.NET Framework .NET 的原始、仅限 Windows 的实现。The original, Windows-only implementation of .NET. “框架”首字母大写。"Framework" is capitalized.
    Target Framework — 目标 Frameworktarget framework .NET 应用或库依赖的 API 集合。The collection of APIs that a .NET app or library relies on. 示例:.NET Core 3.1、.NET Standard 2.0Examples: .NET Core 3.1, .NET Standard 2.0
    目标框架名字对象 (TFM)Target Framework Moniker (TFM) TFM 是一种标准化令牌格式,用于指定 .NET 应用或库的目标框架。A TFM is a standardized token format for specifying the target framework of a .NET app or library. 示例:net462(对于 .NET Framework 4.6.2)。Example: net462 for .NET Framework 4.6.2.
    依赖于框架的应用framework-dependent app 只能在从 .NET 下载页安装了运行时的计算机上运行的应用。An app that can only run on a machine where you've installed the runtime from the .NET download page. 此用法中的“框架”与你从 .NET 下载页下载的“运行时”是相同的。"Framework" in this usage is the same thing as the "runtime" that you download from the .NET download page.
    框架库framework libraries 有时用作运行时库的同义词。Sometimes used as a synonym for runtime libraries.
  • SDKSDK

    上下文Context “SDK”含义"SDK" meaning
    .NET 下载页上的 SDKSDK on the .NET download page 工具和库的集合,你下载和安装它们以开发和运行 .NET 应用。A collection of tools and libraries that you download and install to develop and run .NET apps. 包括 CLI、MSBuild、.NET 运行时和其他组件。Includes the CLI, MSBuild, the .NET runtime, and other components.
    SDK 样式项目SDK-style project 一组 MSBuild 目标和任务,用于指定如何为特定应用类型生成项目。A set of MSBuild targets and tasks that specifies how to build a project for a particular app type. 这种情况下的 SDK 是使用项目文件中 Project 元素的 Sdk 属性指定的。The SDK in this sense is specified by using the Sdk attribute of the Project element in a project file.
  • 平台platform

    上下文Context “平台”含义"platform" meaning
    跨平台cross platform 在此术语中,“平台”表示操作系统以及运行它的硬件,例如 Windows、macOS、Linux、iOS 和 Android。In this term, "platform" means an operating system and the hardware it runs on, such as Windows, macOS, Linux, iOS, and Android.
    .NET 平台.NET platform 用法有所不同。Usage varies. 引用可以是针对 .NET (如 .NET Framework 或 .NET 5)的一种实现,也可以是针对包括所有实现的 .NET 的总体概念。The reference may be to one implementation of .NET (such as .NET Framework or .NET 5) or to an overarching concept of .NET including all implementations.

有关 .NET 术语的详细信息,请参阅 .NET 术语表For more information about .NET terminology, see the .NET glossary.

高级方案Advanced scenarios

以下各部分介绍在一些高级场景中非常有用的 .NET 功能。The following sections explain some capabilities of .NET that are useful in advanced scenarios.

原生互操作Native interop

每个操作系统都有一个应用程序编程接口 (API),用于提供系统服务。Every operating system includes an application programming interface (API) that provides system services. .NET 提供多种方式来调用这些 API。.NET provides several ways to call those APIs.

与原生 API 进行互操作的主要方式是使用“平台调用”,简称 P/Invoke。The main way to interoperate with native APIs is via "platform invoke" or P/Invoke for short. 跨 Linux 和 Windows 平台支持 P/Invoke。P/Invoke is supported across Linux and Windows platforms. 进行互操作的一种仅限 Windows 的方式称为“COM 互操作”,用于在托管代码中操作 COM 组件A Windows-only way of interoperating is known as "COM interop," which works with COM components in managed code. 这种方式建立在 P/Invoke 基础结构之上,但工作原理略有不同。It's built on top of the P/Invoke infrastructure, but it works in subtly different ways.

有关详细信息,请参阅原生互操作性For more information, see Native interoperability.

不安全代码Unsafe code

根据语言支持,CLR 可通过 unsafe 代码访问本机内存和执行指针算术运算。Depending on language support, the CLR lets you access native memory and do pointer arithmetic via unsafe code. 某些算法和系统互操作性需要这些操作。These operations are needed for certain algorithms and system interoperability. 尽管不安全代码的功能强大,但除非有必要与系统 API 互操作或实现最高效的算法,否则不建议使用。Although powerful, use of unsafe code is discouraged unless it's necessary to interoperate with system APIs or implement the most efficient algorithm. 在不同的环境中,不安全代码的执行方式可能不同,使用它还会丧失垃圾回收器和类型安全带来的好处。Unsafe code may not execute the same way in different environments and also loses the benefits of a garbage collector and type safety. 建议尽可能地限制和集中化使用不安全代码,并全面测试该代码。It's recommended to confine and centralize unsafe code as much as possible and test that code thoroughly.

有关详细信息,请参阅不安全代码和指针For more information, see Unsafe code and pointers.

后续步骤Next steps