建立並存執行元件的方針Guidelines for Creating Components for Side-by-Side Execution

請遵循這些一般方針建立為並存執行而設計的 Managed 應用程式或元件:Follow these general guidelines to create managed applications or components designed for side-by-side execution:

  • 將類型識別繫結至特定版本的檔案。Bind type identity to a particular version of a file.

    Common Language Runtime 會使用強式名稱的組件,將類型識別繫結到特定的檔案版本。The common language runtime binds type identity to a particular file version by using strong-named assemblies. 若要建立用於並存執行的應用程式或元件,您必須為所有組件指定強式名稱。To create an application or component for side-by-side execution, you must give all assemblies a strong name. 這會建立精確的類型識別,並確保將任何的類型解析導向到正確的檔案。This creates precise type identity and ensures that any type resolution is directed to the correct file. 強式名稱的組件包含版本、文化特性和發行者資訊,可供執行階段找出符合繫結要求的正確檔案。A strong-named assembly contains version, culture, and publisher information that the runtime uses to locate the correct file to fulfill a binding request.

  • 使用版本感知儲存區。Use version-aware storage.

    此執行階段使用全域組件快取提供版本感知儲存區。The runtime uses the global assembly cache to provide version-aware storage. 全域組件快取是一種版本感知目錄結構,安裝在使用 .NET Framework 的每一台電腦上。The global assembly cache is a version-aware directory structure installed on every computer that uses the .NET Framework. 安裝在全域組件快取的組件不會在安裝該組件新版本時被覆寫。Assemblies installed in the global assembly cache are not overwritten when a new version of that assembly is installed.

  • 建立在隔離狀態執行的應用程式或元件。Create an application or component that runs in isolation.

    在隔離狀態執行的應用程式或元件必須管理資源,以避免該應用程式或元件的兩個執行個體同時執行時產生衝突。An application or component that runs in isolation must manage resources to avoid conflicts when two instances of the application or component are running simultaneously. 應用程式或元件也必須使用版本特定的檔案結構。The application or component must also use a version-specific file structure.

應用程式和元件隔離Application and Component Isolation

隔離是成功設計用於並存執行之應用程式或元件的其中一個關鍵。One key to successfully designing an application or component for side-by-side execution is isolation. 應用程式或元件必須以隔離的方式管理所有資源,尤其是檔案 I/O。The application or component must manage all resources, particularly file I/O, in an isolated manner. 請遵循這些方針,確定您的應用程式或元件在隔離狀態執行:Follow these guidelines to make sure your application or component runs in isolation:

  • 以版本特定的方式寫入登錄。Write to the registry in a version-specific way. 將值儲存在指出此版本的登錄區或機碼中,且不要在各種版本的元件之間共用資訊或狀態。Store values in hives or keys that indicate the version, and do not share information or state across versions of a component. 這可防止同時執行的兩個應用程式或元件覆寫資訊。This prevents two applications or components running at the same time from overwriting information.

  • 使具名的核心物件變成版本特定的物件,讓競爭情形不要發生。Make named kernel objects version-specific so that a race condition does not occur. 例如,當相同應用程式之兩個版本的兩個信號互相等候時就會發生競爭情形。For example, a race condition occurs when two semaphores from two versions of the same application wait on each other.

  • 將檔案和目錄名稱變成版本感知的名稱。Make file and directory names version-aware. 這表示檔案結構應該要依賴版本資訊。This means that file structures should rely on version information.

  • 使用版本特定的方式建立帳戶和群組。Create user accounts and groups in a version-specific manner. 應用程式所建立的使用者帳戶和群組應該以版本識別。User accounts and groups created by an application should be identified by version. 請勿在應用程式版本之間共用使用者帳戶和群組。Do not share user accounts and groups between versions of an application.

安裝和解除安裝版本Installing and Uninstalling Versions

設定用於並存執行的應用程式時,請遵循這些有關安裝及解除安裝版本的方針:When designing an application for side-by-side execution, follow these guidelines concerning installing and uninstalling versions:

  • 請勿從登錄中刪除資訊;其他應用程式在不同版本的 .NET Framework 下執行時可能需要用到這些資訊。Do not delete information from the registry that may be needed by other applications running under a different version of the .NET Framework.

  • 請勿取代登錄中的資訊;其他應用程式在不同版本的 .NET Framework 下執行時可能需要用到這些資訊。Do not replace information in the registry that may be needed by other applications running under a different version of the .NET Framework.

  • 請勿移除註冊 COM 元件;其他應用程式在不同版本的 .NET Framework 下執行時可能需要用到這些資訊。Do not unregister COM components that may be needed by other applications running under a different version of the .NET Framework.

  • 請勿變更 InprocServer32 或已登錄的 COM 伺服器的其他登錄項目。Do not change InprocServer32 or other registry entries for a COM server that was already registered.

  • 請勿刪除使用者帳戶或群組;其他應用程式在不同版本的 .NET Framework 下執行時可能需要用到這些資訊。Do not delete user accounts or groups that may be needed by other applications running under a different version of the .NET Framework.

  • 請勿將任何項目加入包含未建立版本之路徑的登錄。Do not add anything to the registry that contains an unversioned path.

檔案版本號碼和組件版本號碼File Version Number and Assembly Version Number

檔案版本是執行階段不使用的 Win32 版本資源。File version is a Win32 version resource that is not used by the runtime. 一般來說,您甚至可以就地更新檔案版本。In general, you update the file version even for an in-place update. 兩個相同的檔案可以有不同的檔案版本資訊,而兩個不同的檔案也可以有相同的檔案版本資訊。Two identical files can have different file version information, and two different files can have the same file version information.

組件版本可供執行階段用於組件繫結。The assembly version is used by the runtime for assembly binding. 執行階段會將兩個具有不同版本號碼的相同組件視為兩個不同的組件。Two identical assemblies with different version numbers are treated as two different assemblies by the runtime.

當只有檔案版本號碼是新的時,全域組件快取工具 (Gacutil.exe) 可讓您替換組件。The Global Assembly Cache tool (Gacutil.exe) allows you to replace an assembly when only the file version number is newer. 除非組件版本號碼比較高,否則安裝程式通常不會在組件上執行覆寫安裝。The installer generally does not install over an assembly unless the assembly version number is greater.

請參閱See also