.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 Forms 和 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 上的 .NET (RHEL) 。Red 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 平臺上的 .net。Tizen 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 # (發音為「看清晰的」 ) 是新式、物件導向且型別安全的程式設計語言。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 正積極開發新功能,Visual Basic 的語言是穩定的。Unlike C# and F#, for which Microsoft is actively developing new features, the Visual Basic language is stable. Web 應用程式不支援 Visual Basic,但 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 Code (英文)Visual 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. 提供類型系統、元件載入、垃圾收集行程、原生 interop 及其他基本服務。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. 為網際網路連線的應用程式(例如 web 應用程式、IoT 應用程式和行動後端)提供基本的服務。Provides basic services for internet-connected apps, such as web apps, IoT apps, and mobile backends.
  • 桌面執行時間。The desktop runtime. 提供 Windows 傳統型應用程式的基本服務,包括 Windows Forms 和 WPF。Provides basic services for Windows desktop apps, including Windows Forms and WPF.

如需詳細資訊,請參閱下列資源: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>

在這些範例中, Sdk 元素的屬性 Project 會指定一組 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 總覽目標 frameworkFor 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 套件是副檔名為的 .zip 檔案,其中 .nupkg 包含已編譯的程式碼 (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 互動.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 應用程式會在執行時間環境中執行 managed 程式碼 ,此環境稱為 Common Language RUNTIME (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.

如需詳細資訊,請參閱 Common Language Runtime (CLR) 總覽For more information, see Common Language Runtime (CLR) overview.

JIT 編譯程式和 ILJIT compiler and IL

較高階的 .NET 語言 (例如 C#) 可向下編譯成硬體無從驗證的指令集,稱為中繼語言 (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.

如需詳細資訊,請參閱 Managed 執行 程式和階層式 編譯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 的優點,而不會有其缺點。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 就會從 managed 堆積設定物件的記憶體。Each time your code creates a new object, the CLR allocates memory for the object from the managed heap. 只要 Managed 堆積中有可供使用的位址空間,平台就會繼續為新的物件配置空間。As long as address space is available in the managed heap, the runtime continues to allocate space for new objects. 如果沒有足夠的可用位址空間,GC 就會檢查 managed 堆積中,應用程式不再使用的物件。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.

使用 Unmanaged 資源Working with unmanaged resources

有時候,程式碼需要參考 未受管理的資源Sometimes code needs to reference unmanaged resources. Unmanaged 資源是指 .NET 執行階段不會自動維護的資源。Unmanaged resources are resources that aren't automatically maintained by the .NET runtime. 例如檔案控制程式碼就是 Unmanaged 資源。For example, a file handle is an unmanaged resource. FileStream 物件是Managed 物件,但會 Unmanaged 檔案控制代碼。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 中,參考 Unmanaged 資源的物件會實作 IDisposable 介面。In .NET, objects that reference unmanaged resources implement the IDisposable interface. 當您完成使用此物件時,您可以呼叫物件的 Dispose() 方法來釋放任何 Unmanaged 資源。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.

  • 將應用程式發行為與 framework 相依 的應用程式,會產生可執行檔和二進位檔案 (.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. 如需詳細資訊,請參閱 目標 frameworkFor 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/runtime 存放庫中。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)
DependencyInjectionMicrosoft.Extensions.DependencyInjection 相依性插入 (DI)Dependency injection (DI)
Microsoft.Extensions.ConfigurationMicrosoft.Extensions.Configuration 設定Configuration
Microsoft.Extensions.LoggingMicrosoft.Extensions.Logging LoggingLogging
Microsoft. Extensions. 選項Microsoft.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 CoreIn 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

    ContextContext 「執行時間」表示"runtime" meaning
    Common Language Runtime (CLR)Common Language Runtime (CLR) 受管理程式的執行環境。The execution environment for a managed program. 作業系統是執行時間環境的一部分,但不是 .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 server 應用程式和 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

    ContextContext "framework" 意義"framework" meaning
    .NET Framework.NET Framework .NET 的原始、僅限 Windows 的實作為。The original, Windows-only implementation of .NET. "Framework" 為大寫。"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
    Target Framework Moniker (TFM)Target Framework Moniker (TFM) TFM 是標準化的權杖格式,用於指定 .NET 應用程式或程式庫的目標 framework。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 相依的應用程式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 程式庫framework libraries 有時會用來做為 運行時間程式庫的同義字。Sometimes used as a synonym for runtime libraries.
  • SDKSDK

    ContextContext "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 是使用 Sdk 專案檔中專案的屬性所指定 ProjectThe SDK in this sense is specified by using the Sdk attribute of the Project element in a project file.
  • 平台platform

    ContextContext 「平臺」意義"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.

原生 interopNative 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 interop」,可搭配 managed 程式碼中的 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 程式碼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. 雖然功能強大,但不建議使用 unsafe 程式碼,除非它必須與系統 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 程式碼在不同的環境中執行時可能不盡相同,而且也會失去記憶體回收行程和型別安全的好處。Unsafe code may not execute the same way in different environments and also loses the benefits of a garbage collector and type safety. 建議您盡可能限制和集中使用 Unsafe 程式碼,並徹底測試該程式碼。It's recommended to confine and centralize unsafe code as much as possible and test that code thoroughly.

如需詳細資訊,請參閱 Unsafe 程式碼和指標For more information, see Unsafe code and pointers.

後續步驟Next steps