Common Language Runtime 中的組件Assemblies in the Common Language Runtime

組件是 .NET Framework 應用程式的建置組塊;它們構成部署、版本控制、重複使用、啟用範圍和安全性權限的基礎單位。Assemblies are the building blocks of .NET Framework applications; they form the fundamental unit of deployment, version control, reuse, activation scoping, and security permissions. 組件是建置來共同運作及構成一個功能邏輯單位的型別與資源集合。An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality. 組件為通用語言執行平台提供了感知型別實作所需的資訊。An assembly provides the common language runtime with the information it needs to be aware of type implementations. 對於執行階段而言,型別不會存在於組件的內容以外。To the runtime, a type does not exist outside the context of an assembly.

組件可以執行以下功能:An assembly performs the following functions:

  • 組件包含通用語言執行平台執行的程式碼。It contains code that the common language runtime executes. 如果組件沒有相關聯的組件資訊清單,則不會執行可攜式執行檔 (PE) 中的 Microsoft 中繼語言 (MSIL) 程式碼。Microsoft intermediate language (MSIL) code in a portable executable (PE) file will not be executed if it does not have an associated assembly manifest. 請注意,每個組件只能有一個進入點 (DllMainWinMainMain)。Note that each assembly can have only one entry point (that is, DllMain, WinMain, or Main).

  • 組件可構成安全性界限。It forms a security boundary. 組件是要求和授與權限的單位。An assembly is the unit at which permissions are requested and granted. 如需套用至組件之安全性界限的詳細資訊,請參閱組件安全性考量For more information about security boundaries as they apply to assemblies, see Assembly Security Considerations.

  • 組件可構成型別界限。It forms a type boundary. 每種型別的識別都包含該型別所在之組件的名稱。Every type's identity includes the name of the assembly in which it resides. 在某個組件範圍中載入的型別 MyType 與在另一個組件範圍中載入的型別 MyType 不同。A type called MyType that is loaded in the scope of one assembly is not the same as a type called MyType that is loaded in the scope of another assembly.

  • 組件可構成參考範圍界限。It forms a reference scope boundary. 組件的資訊清單含有用來解析型別和滿足資源要求的組件中繼資料。The assembly's manifest contains assembly metadata that is used for resolving types and satisfying resource requests. 它會指定公開於組件之外的型別和資源。It specifies the types and resources that are exposed outside the assembly. 資訊清單也會列舉組件相依的其他組件。The manifest also enumerates other assemblies on which it depends.

  • 組件可構成版本界限。It forms a version boundary. 組件是通用語言執行平台中可控制版本的最小單位;在同一組件中的所有型別和資源會當做一個單位來控制版本。The assembly is the smallest versionable unit in the common language runtime; all types and resources in the same assembly are versioned as a unit. 組件的資訊清單描述您對任何相依組件所指定的版本相依性。The assembly's manifest describes the version dependencies you specify for any dependent assemblies. 如需版本控制的詳細資訊,請參閱組件版本控制For more information about versioning, see Assembly Versioning.

  • 組件可構成部署單位。It forms a deployment unit. 當應用程式啟動時,一定要有應用程式一開始所呼叫的組件。When an application starts, only the assemblies that the application initially calls must be present. 至於其他組件 (例如當地語系化資源或含有公用程式類別的組件),則可視需要擷取。Other assemblies, such as localization resources or assemblies containing utility classes, can be retrieved on demand. 如此可讓應用程式在第一次下載時保持最簡狀態。This allows applications to be kept simple and thin when first downloaded. 如需部署組件的詳細資訊,請參閱部署應用程式For more information about deploying assemblies, see Deploying Applications.

  • 組件是支援並存執行的單位。It is the unit at which side-by-side execution is supported. 如需執行多個組件版本的詳細資訊,請參閱組件和並存執行For more information about running multiple versions of an assembly, see Assemblies and Side-by-Side Execution.

組件可以是靜態,也可以是動態。Assemblies can be static or dynamic. 靜態組件可以包含 .NET Framework 型別 (介面和類別),以及組件的資源 (點陣圖、JPEG 檔案、資源檔案等)。Static assemblies can include .NET Framework types (interfaces and classes), as well as resources for the assembly (bitmaps, JPEG files, resource files, and so on). 靜態組件儲存在磁碟上的可攜式執行檔 (PE) 中。Static assemblies are stored on disk in portable executable (PE) files. 您也可以使用 .NET Framework 建立動態組件,直接從記憶體執行,並且執行前不會儲存至磁碟。You can also use the .NET Framework to create dynamic assemblies, which are run directly from memory and are not saved to disk before execution. 您可以在執行動態組件之後,再將其儲存至磁碟。You can save dynamic assemblies to disk after they have executed.

您可以使用幾種方式建立組件。There are several ways to create assemblies. 您可以使用過去用來建立 .dll 或 .exe 檔案的開發工具,例如 Visual Studio。You can use development tools, such as Visual Studio, that you have used in the past to create .dll or .exe files. 您可以使用 Windows SDK 中提供的工具,搭配其他開發環境中建立的模組來建立組件。You can use tools provided in the Windows SDK to create assemblies with modules created in other development environments. 您也可以使用 Common Language Runtime API (例如 System.Reflection.Emit) 來建立動態組件。You can also use common language runtime APIs, such as System.Reflection.Emit, to create dynamic assemblies.

標題Title 說明Description
組件內容Assembly Contents 描述構成組件的項目。Describes the elements that make up an assembly.
組件資訊清單Assembly Manifest 描述組件資訊清單中的資料,以及這些資料在組件中的儲存方式。Describes the data in the assembly manifest, and how it is stored in assemblies.
全域組件快取Global Assembly Cache 描述全域組件快取,以及如何搭配組件使用。Describes the global assembly cache and how it is used with assemblies.
強式名稱的組件Strong-Named Assemblies 描述強式名稱的組件之特性。Describes the characteristics of strong-named assemblies.
組件安全性考量Assembly Security Considerations 討論組件安全性的運作方式。Discusses how security works with assemblies.
組件版本控制Assembly Versioning 提供 .NET Framework 版本控制原則的概觀。Provides an overview of the .NET Framework versioning policy.
組件定位Assembly Placement 討論組件的位置。Discusses where to locate assemblies.
組件和並存執行Assemblies and Side-by-Side Execution 提供同時使用執行階段或組件之多個版本的概觀。Provides an overview of using multiple versions of the runtime or of an assembly simultaneously.
使用組件設計程式Programming with Assemblies 描述如何建立和簽署組件,以及如何設定組件屬性。Describes how to create, sign, and set attributes on assemblies.
發出動態方法和組件Emitting Dynamic Methods and Assemblies 描述如何建立動態組件。Describes how to create dynamic assemblies.
執行階段如何找出組件How the Runtime Locates Assemblies 描述 .NET Framework 如何在執行階段中解析組件參考。Describes how the .NET Framework resolves assembly references at run time.

參考資料Reference

System.Reflection.Assembly