發佈 Managed Windows 執行階段元件Distributing a managed Windows Runtime Component

您可以透過檔案複製來發佈自己的 Windows 執行階段元件。You can distribute your Windows Runtime Component by file copy. 不過,如果元件包含許多檔案,使用者就必須等待冗長的安裝過程。However, if your component consists of many files, installation can be tedious for your users. 此外,放置檔案時發生的錯誤或參考設定失敗都可能會造成他們的問題。Also, errors in placing files or failure to set references might cause problems for them. 您可以將複雜元件封裝成 Visual Studio 擴充功能 SDK,方便安裝與使用。You can package a complex component as a Visual Studio extension SDK, to make it easy to install and use. 使用者只需為整個封裝設定一個參考。Users only need to set one reference for the entire package. 您可以使用 [ 擴充功能和更新 ] 對話方塊輕鬆地尋找並安裝您的元件,如 尋找和使用 Visual Studio 擴充功能中所述。They can easily locate and install your component by using the Extensions and Updates dialog box, as described in Finding and Using Visual Studio Extensions.

規劃可發佈的 Windows 執行階段元件Planning a distributable Windows Runtime Component

為二進位檔案 (例如您的 .winmd 檔案) 選擇唯一的名稱。Choose unique names for binary files, such as your .winmd files. 建議您遵循下列格式,以確保名稱的唯一性:We recommend the following format to ensure uniqueness:

company.product.purpose.extension
For example: Microsoft.Cpp.Build.dll

您的二進位檔案將安裝於 app 封裝中,可能會與其他開發人員的二進位檔案放在一起。Your binary files will be installed in app packages, possibly with binary files from other developers. 請參閱 如何:建立軟體發展工具組中的「擴充功能 sdk」。See "Extension SDKs" in How to: Create a Software Development Kit.

請先考慮元件的複雜性,再決定其發佈方式。To decide how to distribute your component, consider how complex it is. 符合下列條件時,建議使用擴充功能 SDK 或類似的封裝管理員:An extension SDK or similar package manager is recommended when:

  • 您的元件包含多個檔案。Your component consists of multiple files.
  • 您為多個平台 (例如 x86 和 ARM) 提供不同的元件版本。You provide versions of your component for multiple platforms (x86 and ARM, for example).
  • 您同時提供元件的偵錯與發行版本。You provide both debug and release versions of your component.
  • 您的元件包含只能在設計階段使用的檔案和組件。Your component has files and assemblies that are used only at design time.

如果符合上述多個條件,擴充功能 SDK 就特別有用。An extension SDK is particularly useful if more than one of the above are true.

注意   針對複雜的元件,NuGet 套件管理系統提供延伸模組 Sdk 的開放原始碼替代方案。Note  For complex components, the NuGet package management system offers an open source alternative to extension SDKs. 與擴充功能 SDK 一樣,NuGet 可讓您建立封裝來簡化複雜元件的安裝作業。Like extension SDKs, NuGet enables you to create packages that simplify the installation of complex components. 如需 NuGet 套件和 Visual Studio 擴充功能 sdk 的比較,請參閱 使用 NuGet 與擴充功能 sdk 來新增參考For a comparison of NuGet packages and Visual Studio extension SDKs, see Adding References Using NuGet Versus an Extension SDK.

藉由檔案複製發佈Distribution by file copy

如果元件是由單一 .winmd 檔案組成,或是由 .winmd 檔案和資源索引 (.pri) 檔案組成,您只需讓使用者複製 .winmd 檔案即可。If your component consists of a single .winmd file, or a .winmd file and a resource index (.pri) file, you can simply make the .winmd file available for users to copy. 使用者可以將檔案放在專案中的任何地方、使用 [加入現有項目] 對話方塊來將 .winmd 檔案加入專案,然後使用 [參考管理員] 對話方塊來建立參考。Users can put the file wherever they want to in a project, use the Add Existing Item dialog box to add the .winmd file to the project, and then use the Reference Manager dialog box to create a reference. 如果您包含 .pri 檔案或 .xml 檔案,請告知使用者將這些檔案與 .winmd 檔案放在一起。If you include a .pri file or an .xml file, instruct users to place those files with the .winmd file.

注意   當您建立 Windows 執行階段元件時,Visual Studio 一律會產生 pri 檔案,即使您的專案不包含任何資源也一樣。Note  Visual Studio always produces a .pri file when you build your Windows Runtime Component, even if your project doesn't include any resources. 如果您有適用于元件的測試應用程式,您可以在 bin \ debug AppX 資料夾中檢查應用程式封裝的內容,以判斷是否使用此 pri 檔案。 \If you have a test app for your component, you can determine whether the .pri file is used by examining the contents of the app package in the bin\debug\AppX folder. 如果來自元件的 .pri 檔案並未出現在其中,則您就不需發佈該元件。If the .pri file from your component doesn't appear there, you don't need to distribute it. 或者,您也可以使用 MakePRI.exe 工具,傾印來自於 Windows 執行階段元件專案的資源檔。Alternatively, you can use the MakePRI.exe tool to dump the resource file from your Windows Runtime Component project. 例如,您可以在 Visual Studio 命令提示字元視窗中輸入: makepri dump /if MyComponent.pri /of MyComponent.pri.xml 如需 .pri 檔案的詳細資訊,請參閱資源管理系統 (Windows)For example, in the Visual Studio Command Prompt window, type: makepri dump /if MyComponent.pri /of MyComponent.pri.xml You can read more about .pri files in Resource Management System (Windows).

藉由擴充功能 SDK 發佈Distribution by extension SDK

複雜元件通常包括 Windows 資源,但請參閱上一節中關於偵測空白 .pri 檔案的注意事項。A complex component usually includes Windows resources, but see the note about detecting empty .pri files in the previous section.

建立擴充功能 SDKTo create an extension SDK

  1. 確定您已安裝 Visual Studio SDK。Make sure you have the Visual Studio SDK installed. 您可以從 Visual Studio 下載頁面下載 Visual Studio SDK。You can download the Visual Studio SDK from the Visual Studio Downloads page.

  2. 使用 VSIX 專案範本建立新專案。Create a new project using the VSIX Project template. 您可以在 Visual C# 或 Visual Basic 底下的 [擴充性] 分類中找到此範本。You can find the template under Visual C# or Visual Basic, in the Extensibility category. 此範本是隨著 Visual Studio SDK 一起安裝。This template is installed as part of the Visual Studio SDK. (逐步解說:使用 C# 或 Visual Basic 建立 SDK逐步解說:使用 C++ 建立 SDK 會透過非常簡單的案例,來示範此範本的使用方式。(Walkthrough: Creating an SDK using C# or Visual Basic or Walkthrough: Creating an SDK using C++, demonstrates the use of this template in a very simple scenario. ))

  3. 判斷 SDK 的資料夾結構。Determine the folder structure for your SDK. 資料夾結構的開頭位於 VSIX 專案的根層級,並且包含 ReferencesRedistDesignTime 資料夾。The folder structure begins at the root level of your VSIX project, with the References, Redist, and DesignTime folders.

    • References 是二進位檔案的位置,您的使用者可以針對這些檔案進行程式設計。References is the location for binary files that your users can program against. 擴充功能 SDK 會在使用者的 Visual Studio 專案中建立這些檔案的參考。The extension SDK creates references to these files in your users' Visual Studio projects.
    • Redist 是必須與二進位檔案一同發佈之其他檔案的位置,位於使用您元件所建立的 app 中。Redist is the location for other files that must be distributed with your binary files, in apps that are created by using your component.
    • DesignTime 是只有當開發人員在建立會用到您元件的 app 時所使用之檔案的位置。DesignTime is the location for files that are used only when developers are creating apps that use your component.

    您可以在上述每一個資料夾中建立組態資料夾。In each of these folders, you can create configuration folders. 可以使用的名稱包含 debug、retail 和 CommonConfiguration。The permitted names are debug, retail, and CommonConfiguration. CommonConfiguration 資料夾是用來存放零售或偵錯組建所使用的相同檔案。The CommonConfiguration folder is for files that are the same whether they're used by retail or debug builds. 如果您只發佈元件的零售組建,就能將所有檔案放在 CommonConfiguration 中,然後省略另外兩個資料夾。If you're only distributing retail builds of your component, you can put everything in CommonConfiguration and omit the other two folders.

    在每個組態資料夾中,您可以針對平台特定的檔案提供架構資料夾。In each configuration folder, you can provide architecture folders for platform-specific files. 如果您針對所有平台使用相同的檔案,則可提供名為 neutral 的單一資料夾。If you use the same files for all platforms, you can supply a single folder named neutral. 您可以在 how to:建立軟體發展工具組中,找到資料夾結構的詳細資料,包括其他架構資料夾名稱。You can find details of the folder structure, including other architecture folder names, in How to: Create a Software Development Kit. (該文章將討論平台 SDK 和擴充功能 SDK。(That article discusses both platform SDKs and extension SDKs. 您可能發現摺疊關於平台 SDK 的章節,可有效避免混淆。You may find it useful to collapse the section about platform SDKs, to avoid confusion. ))

  4. 建立 SDK 資訊清單檔案。Create an SDK manifest file. 資訊清單會指定名稱和版本資訊、您的 SDK 支援的架構、.NET 版本,以及 Visual Studio 使用 SDK 之方式的其他相關資訊。The manifest specifies name and version information, the architectures your SDK supports, .NET versions, and other information about the way Visual Studio uses your SDK. 如需詳細資訊和範例,請參閱做法:建立軟體開發套件You can find details and an example in How to: Create a Software Development Kit.

  5. 建置和發佈擴充功能 SDK。Build and distribute the extension SDK. 如需深入的資訊,包括當地語系化和簽署 VSIX 封裝,請參閱 Vsix 部署For in-depth information, including localizing and signing the VSIX package, see VSIX Deployment.