建立 Office 方案Build Office solutions

一般而言,建置和偵錯 Office 專案,和在 Visual Studio 中建置和偵錯其他類型的專案是相同的,例如 Windows Forms。In general, building and debugging Office projects is the same as building and debugging other types of projects in Visual Studio, such as Windows Forms. 本節主題會說明兩者之間的差異。The topics in this section explain the differences that do exist. 如需如何建立應用程式的一般資訊,請參閱 Visual Studio 中的編譯和建立For general information about how to build applications, see Compile and build in Visual Studio.

注意

有興趣開發跨多個平臺擴充 Office 體驗的解決方案嗎?Interested in developing solutions that extend the Office experience across multiple platforms? 查看新的 Office 增益集模型Check out the new Office Add-ins model. 相較于 VSTO 增益集和方案,Office 增益集的使用量較小,而且您可以使用幾乎任何 web 程式設計技術(例如 HTML5、JavaScript、CSS3 和 XML)來建立這些增益集。Office Add-ins have a small footprint compared to VSTO Add-ins and solutions, and you can build them by using almost any web programming technology, such as HTML5, JavaScript, CSS3, and XML.

Office 專案的專案輸出Project output for Office projects

Office 專案的輸出位置是 projectname\bin\release 或 projectname\bin\debug。The output location for Office projects is projectname\bin\release or projectname\bin\debug. 無法建立到部署目錄。You cannot build to a deployment directory.

檔層級專案Document-level projects

當您建置文件層級專案時,專案輸出會包含下列項目:When you build a document-level project, the following items are included in the project output:

  • 一份專案文件的複本。A copy of the project document.

  • 其 [複製到本機] 屬性設定為 true 的專案組件和所有參考組件。The project assembly and all referenced assemblies that have their Copy Local property set to true.

  • 應用程式資訊清單,其副檔名為 .manifestThe application manifest, which has the file name extension .manifest. 如需詳細資訊,請參閱 Office 方案的應用程式資訊清單For more information, see Application manifests for Office solutions.

  • 具有副檔名 vsto 的部署資訊清單。The deployment manifest, which has the file name extension .vsto. 如需詳細資訊,請參閱 Office 方案的部署資訊清單For more information, see Deployment manifests for Office solutions.

  • 程式資料庫 (PDB) 檔。A program database (PDB) file.

注意

文件層級解決方案如果建立在遠端位置而不是本機電腦,請在應用程式信任中心的 [信任位置] 清單中加入完整的路徑。If you build a document-level solution to a remote location instead of the local computer, add the fully qualified path to the Trusted Locations list in the application's Trust Center. 如需詳細資訊,請參閱將信任授與 安全 Office 方案中的檔一節。For more information, see the section called Granting Trust to Documents in Secure Office solutions.

應用層級專案Application-level projects

當您建立 VSTO 增益集專案時,專案輸出中會包含下列專案:When you build a VSTO Add-in project, the following items are included in the project output:

  • 其 [複製到本機] 屬性設定為 true 的專案組件和所有參考組件。The project assembly and all referenced assemblies that have their Copy Local property set to true.

  • 應用程式資訊清單,其副檔名為 .manifestThe application manifest, which has the file name extension .manifest. 如需詳細資訊,請參閱 Office 方案的應用程式資訊清單For more information, see Application manifests for Office solutions.

  • 具有副檔名 vsto 的部署資訊清單。The deployment manifest, which has the file name extension .vsto. 如需詳細資訊,請參閱 Office 方案的部署資訊清單For more information, see Deployment manifests for Office solutions.

  • 專案元件的程式資料庫 (PDB) 檔。A program database (PDB) file for the project assembly.

    VSTO 增益集專案的建置程序也會在需要載入 VSTO 增益集的開發電腦上建立一組登錄項目。The build process for VSTO Add-in projects also creates a set of registry entries on the development computer that are required to load the VSTO Add-in. 如需詳細資訊,請參閱 VSTO 增益集的登錄專案For more information, see Registry entries for VSTO Add-ins.

    如果您建置了包含表單區域的 Outlook VSTO 增益集專案,建置程序會在登錄中加入以下額外的資訊:If you build an Outlook VSTO Add-in project that contains form regions, the build process adds the following additional information to the registry:

  • 與一個或多個表單區域關聯之每個訊息類別的索引鍵。A key for each message class that is associated with one or more form regions.

  • 每個表單區域的項目,以及代表 Outlook VSTO 增益集名稱的關聯值。An entry for each form region and an associated value that represents the name of the Outlook VSTO Add-in.

    Outlook 需要這項資訊載入表單區域。Outlook needs this information to load the form regions.

參考的組件Referenced assemblies

您可以參考您「建置 Office 解決方案」專案的組件 (包括類別庫專案)。You can reference assemblies (including class library projects) from your Building Office Solutions project. 每個參考的組件都有稱為 [複製到本機] 的屬性。Every referenced assembly has a property called Copy Local. [複製到本機] 指出組件是否要複製到輸出目錄。Copy Local indicates whether the assembly is copied to the output directory. 依預設,它會設定為 trueBy default it is set to true. 每個將 [複製到本機] 設為 true 的參考組件都會複製到輸出目錄。Every referenced assembly that has Copy Local set to true is copied to the output directory.

組建流程期間的安全性Security during the build process

Visual Studio 會自動設定開發電腦的安全性設定,在建置程序期間將信任授與解決方案。Visual Studio automatically configures the security settings on the development computer to grant trust to the solution during the build process. 這讓解決方案在被偵錯時依然執行。This allows the solution to run while you debug it.

Office 專案使用憑證來驗證發行者。Office projects use certificates to verify the publisher. Visual Studio 會自動建立暫時憑證以識別 Office 解決方案,並設定開發電腦信任暫時的憑證。Visual Studio automatically creates a temporary certificate to identify Office solutions, and configures the development computer to trust the temporary certificate.

如需詳細資訊,請參閱 安全的 Office 方案For more information, see Secure Office solutions.

網路專案Network projects

如果組件或文件位置位在網路共用上,則本機 (使用者層級) 的安全性原則更新將不足以允許解決方案執行。If the assembly or document location is on a network share, the local (User level) security policy update is not enough to allow the solution to run. 系統管理員必須先將電腦層級的完全信任授與網路共用上的組件和文件,解決方案才會執行。An administrator must grant full trust at the Machine level to assemblies and documents that are on a network share before the solution will run. 如需如何設定安全性原則的詳細資訊,請參閱 安全的 Office 方案For more information about how to set security policy, see Secure Office solutions.

針對文件層級專案,您也必須在 Office 的信任資料夾清單中加入文件的完整路徑位置。For document-level projects, you must also add the fully qualified location of the document to the Office trusted folders list. 如需詳細資訊,請參閱 授與信任給檔For more information, see Grant trust to documents.

變更平臺目標Change the platform target

Office 專案的平台目標預設是 任何 CPUBy default, the platform target for Office projects is Any CPU. 通常不應該變更這項設定。Typically, you should not change this setting. 使用平台目標設定為 任何 CPU 所建置的 Office 解決方案,可在 32 位元和 64 位元版本的 Microsoft Office 2013Office 2013Office 2010Office 2010中執行。Office solutions that are built with the Any CPU platform target setting run in 32-bit and 64-bit versions of Microsoft Office 2013Office 2013 or Office 2010Office 2010.

只有建立只能在 64 位元版本的 Microsoft Office 2013Office 2013Office 2010Office 2010中執行的解決方案時,才將平台目標設定為 x64,而這種解決方案需要原生的 64 位元應用程式開發介面。You should set the platform target to x64 only if you are creating a solution that will run only in 64-bit versions of Microsoft Office 2013Office 2013 or Office 2010Office 2010, and your solution calls native 64-bit APIs. 如需變更平臺目標設定的詳細資訊,請參閱 如何:將專案設定成以平臺為目標For more information about changing the platform target setting, see How to: Configure projects to target platforms.

如果平台目標設定為 x64,解決方案就不能在 32 位元版本的 Windows 或 Office 中執行。If you set the platform target to x64, the solution will not run in 32-bit versions of Windows or Office. X64 平台目標需要解決方案在 64 位元處理序中執行。The x64 platform target requires the solution to run in a 64-bit process.

使用 Clean 命令Use the Clean command

若要從開發電腦中移除已建置的專案檔案,您可以使用 之 [建置]****功能表的 [清除]Visual StudioVisual Studio命令。To remove the built project files from the development computer, you can use the Clean command on the Build menu in Visual StudioVisual Studio. [清除] 命令會刪除建置輸出位置的所有檔案。The Clean command deletes all files in the build output location. 至於應用程式層級專案,[清除] 命令也會移除建置程序所建立的登錄項目。For application-level projects, the Clean command also removes the registry entries that are created by the build process.

標題Title 描述Description
Debug Office 專案Debug Office projects 列出偵錯 Office 專案的相關問題。Presents issues involved in debugging Office projects.
逐步解說:建立 Excel 的第一個檔層級自訂Walkthrough: Create your first document-level customization for Excel 示範如何建立 Excel 的基本文件層級自訂。Demonstrates how to create a basic document-level customization for Excel.
如何:重新啟用已停用的 VSTO 增益集How to: Re-enable a VSTO Add-in that has been disabled 說明如何重新啟用已硬式或已停用的 VSTO 增益集。Describes how to re-enable a VSTO Add-in that has been hard or soft disabled.
設計和建立 Office 方案Design and create Office solutions 提供建立 Office 解決方案以及解決方案之組件角色相關資訊的連結。Provides links to information about creating Office solutions, and about the role of assemblies in your solution.