逐步解說:在單一 ClickOnce 安裝程式中部署多個 Office 方案

您可以在單一套件中部署多個 Office 方案,簡化安裝和升級程序。 在發行之後及安裝之前,您都必須修改和重新簽署應用程式和部署資訊清單。

適用於: 本主題中的資訊適用於 Microsoft Office 2013 Preview 和 Microsoft Office 2010 的文件層級專案和應用程式層級專案。如需詳細資訊,請參閱 依 Office 應用程式和專案類型提供的功能

這個逐步解說將說明下列工作:

  • 建立多個 Office 方案.

  • 修改應用程式資訊清單.

  • 重新簽署資訊清單.

注意事項注意事項

在下列指示的某些 Visual Studio 使用者介面項目中,您的電腦可能會顯示不同的名稱或位置:您所擁有的 Visual Studio 版本以及使用的設定會決定這些項目。如需詳細資訊,請參閱 Visual Studio 設定

必要條件

您需要下列元件才能完成此逐步解說:

-

包含 Microsoft Office Developer 工具的 Visual Studio 2012 版本。如需詳細資訊,請參閱[設定電腦以開發 Office 方案](https://msdn.microsoft.com/zh-tw/library/bb398242\(v=vs.110\))。
  • Word 2013 預覽

  • Outlook 2013 預覽

  • Excel 2013 預覽

  • Word 2010

  • Outlook 2010

  • Excel 2010

  • 測試用電腦。

建立多個 Office 方案

一開始先建立三個 Office 專案,其中一個做為安裝程式, 其他兩個將會部署至使用者電腦。

若要建立和開發 Word、Outlook 和 Excel 專案

  1. 建立 Word 文件層級專案。 將專案命名為 ContosoInstaller,然後儲存在 %USERPROFILE%\Documents\Visual Studio 2012\Projects 目錄中。

    ContosoInstaller 專案將用來做為安裝程式。 如需詳細資訊,請參閱HOW TO:在 Visual Studio 中建立 Office 專案

  2. 在 ContosoInstaller 方案中,新增名為 ContosoOutlookAddIn 的 Outlook 應用程式層級專案,再將您的程式碼加入至這個 Outlook 專案。

  3. 在 ContosoInstaller 方案中,新增名為 ContosoExcelWorkbook 的 Excel 文件層級專案,再將您的程式碼加入至這個 Excel 專案。

發行 Office 方案

使用 [發行精靈] 或 [專案設計工具] 的 [專案頁],將這兩個 Office 方案發行至開發電腦。

若要建發行 Word、Outlook 和 Excel 專案

  1. 將 ContosoInstaller 專案發行至 c:\publish 資料夾。 如需詳細資訊,請參閱HOW TO:使用 ClickOnce 發行 Office 方案

  2. 將 ContosoOutlookAddIn 專案發行至 c:\publish 資料夾。

  3. 將 ContosoExcelWorkbook 專案發行至 c:\publish 資料夾。

修改應用程式資訊清單

使用 Visual Studio 的 XML 編輯器將安裝相依性、檔案、進入點和組件加入至應用程式資訊清單。 應用程式資訊清單的內容類似於物料清單,它會列出箱子的整個內容;應用程式資訊清單會列出所有相依性及必備的組件,以及應用程式所需要的檔案。 Office 方案的應用程式資訊清單也會列出 Office 應用程式應該針對應用程式層級增益集和文件層級自訂載入的組件。

Dd465290.collapse_all(zh-tw,VS.110).gif加入安裝相依性

修改應用程式資訊清單以安裝 ContosoOutlookAddin 和 ContosoExcelWorkbook 組件,並移除 ContosoInstaller 組件的參考。

若要將安裝相依性加入至應用程式資訊清單

  1. 將 ContosoOutlookAddIn_1_0_0_0 和 ContosoExcelWorkbook_1_0_0_0 目錄的內容從 c:\publish\Application Files 資料夾移至 ContosoInstaller_1_0_0_0 目錄。

  2. 使用 XML 編輯器開啟 ContosoInstaller.dll.manifest、ContosoOutlookAddIn.dll.manifest 和 ContosoExcelWorkbook.dll.manifest 檔案。

  3. 從 ContosoOutlookAddIn.dll.manifest 檔案,複製包含 ContosoOutlookAddIn.dll 在內的所有安裝和檔案相依性。 也就是,複製所有以 <dependentAssembly dependencyType="install" 或 <file name="app.config"> 開頭的相依性。 您的程式碼應該看起來如下:只 <dsig:DigestValue> 項目而異。

      <dependency>
        <dependentAssembly 
           dependencyType="install"
           allowDelayedBinding="true" 
           codebase="Microsoft.Office.Tools.Common.v4.0.Utilities.dll" 
           size="30816">
          <assemblyIdentity 
            name="Microsoft.Office.Tools.Common.v4.0.Utilities" 
            version="10.0.0.0"
            publicKeyToken="B03F5F7F11D50A3A"
            language="neutral"
            processorArchitecture="msil" />
          <hash>
            <dsig:Transforms>
              <dsig:Transform
                Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
            </dsig:Transforms>
            <dsig:DigestMethod 
              Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
            <dsig:DigestValue>Ki0…</dsig:DigestValue>
          </hash>
        </dependentAssembly>
      </dependency>
      <dependency>
        <dependentAssembly
          dependencyType="install"
          allowDelayedBinding="true" 
          codebase="Microsoft.Office.Tools.Outlook.v4.0.Utilities.dll"   
          size="47200">
          <assemblyIdentity 
            name="Microsoft.Office.Tools.Outlook.v4.0.Utilities" 
            version="10.0.0.0"
            publicKeyToken="B03F5F7F11D50A3A"
            language="neutral" 
            processorArchitecture="msil" />
          <hash>
            <dsig:Transforms>
              <dsig:Transform
                Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
            </dsig:Transforms>
            <dsig:DigestMethod 
              Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
            <dsig:DigestValue>050...</dsig:DigestValue>
          </hash>
        </dependentAssembly>
      </dependency>
      <dependency>
        <dependentAssembly
          dependencyType="install" 
          allowDelayedBinding="true"
          codebase="ContosoOutlookAddIn.dll"
          size="10240">
          <assemblyIdentity
            name="ContosoOutlookAddIn" 
            version="1.0.0.0" 
            language="neutral" 
            processorArchitecture="msil" />
          <hash>
            <dsig:Transforms>
              <dsig:Transform Algorithm=
                "urn:schemas-microsoft-com:HashTransforms.Identity" />
            </dsig:Transforms>
            <dsig:DigestMethod Algorithm=
              "http://www.w3.org/2000/09/xmldsig#sha1" />
            <dsig:DigestValue>i4e</dsig:DigestValue>
          </hash>
        </dependentAssembly>
      </dependency>
      <file name="ContosoOutlookAddIn.dll.config" size="77">
        <hash>
          <dsig:Transforms>
            <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
          </dsig:Transforms>
          <dsig:DigestMethod 
             Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
          <dsig:DigestValue>w7W...</dsig:DigestValue>
        </hash>
      </file>
    
  4. 在 ContosoInstaller.dll.manifest 檔案的相依性區段結尾處貼上 ContosoOutlookAddIn.dll 安裝相依性。

  5. 從 ContosoExcelWorkbook.dll.manifest 檔案複製所有安裝和檔案相依性,包括 ContosoExcelWorkbook.dll 和 Microsoft.Office.Tools.Common.v4.0.Utilities.dll。 也就是,複製所有以 <dependentAssembly dependencyType="install" 或 <file name="app.config"> 開頭的相依性。 您的程式碼應該看起來如下:只 <dsig:DigestValue> 項目而異。

      <dependency>
        <dependentAssembly
          dependencyType="install"
          allowDelayedBinding="true"
          codebase="ContosoExcelWorkbook.dll"
          size="12800">
          <assemblyIdentity
            name="ContosoExcelWorkbook" 
            version="1.0.0.0"
            language="neutral"
            processorArchitecture="msil" />
          <hash>
            <dsig:Transforms>
              <dsig:Transform Algorithm=
                "urn:schemas-microsoft-com:HashTransforms.Identity" />
            </dsig:Transforms>
            <dsig:DigestMethod Algorithm=
              "http://www.w3.org/2000/09/xmldsig#sha1" />
            <dsig:DigestValue>i4e</dsig:DigestValue>
          </hash>
        </dependentAssembly>
      </dependency>
      <dependency>
        <dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="Microsoft.Office.Tools.Common.v4.0.Utilities.dll" size="30816">
          <assemblyIdentity name="Microsoft.Office.Tools.Common.v4.0.Utilities" version="10.0.0.0" publicKeyToken="B03F5F7F11D50A3A" language="neutral" processorArchitecture="msil" />
          <hash>
            <dsig:Transforms>
              <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
            </dsig:Transforms>
            <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
            <dsig:DigestValue>Ki0A9wOpes1YX5NaAvjmUeFSh0g=</dsig:DigestValue>
          </hash>
        </dependentAssembly>
      </dependency>
      <dependency>
        <dependentAssembly
          dependencyType="install"
          allowDelayedBinding="true" 
          codebase="Microsoft.Office.Tools.Excel.v4.0.Utilities.dll" 
          size="235104">
          <assemblyIdentity 
            name="Microsoft.Office.Tools.Excel.v4.0.Utilities" 
            version="10.0.0.0"
            publicKeyToken="B03F5F7F11D50A3A"
            language="neutral"
            processorArchitecture="msil" />
          <hash>
            <dsig:Transforms>
              <dsig:Transform
               Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
            </dsig:Transforms>
            <dsig:DigestMethod 
              Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
            <dsig:DigestValue>Te/...</dsig:DigestValue>
          </hash>
        </dependentAssembly>
      </dependency>
      <file name=" ContosoExcelWorkbook.dll.config" size="77">
        <hash>
          <dsig:Transforms>
            <dsig:Transform
             Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
          </dsig:Transforms>
          <dsig:DigestMethod 
            Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
          <dsig:DigestValue>w7W...</dsig:DigestValue>
        </hash>
      </file>
    
  6. 在 ContosoInstaller.dll.manifest 檔案的相依性區段結尾處貼上安裝相依性。

  7. 在 ContosoInstaller.dll.manifest 檔案中,移除 ContosoInstaller.dll 和 Microsoft.Office.Tools.Word.v4.0.Utilities.dll 安裝相依性。 同時也移除任何重複的相依性。 例如,您可能複製了多個 Microsoft.Office.Tools.Common.v4.0.Utilities.dll 的安裝相依性。

    注意事項注意事項

    如果您是在部署 Word 文件層級的方案,則在最後的資訊清單中保留 Microsoft.Office.Tools.Word.v4.0.Utilities.dll。

Dd465290.collapse_all(zh-tw,VS.110).gif加入進入點

修改應用程式資訊清單,以便將 ContosoOutlookAddin 和 ContosoExcelWorkbook 組件載入至 <vstav3> 命名空間。

若要將 vstav3 命名空間中的進入點加入至應用程式資訊清單

  1. 在 ContosoInstaller.dll.manifest 檔案中,移除介於 <vstav3:entryPointsCollection> 和 </vstav3:entryPointsCollection> 項目之間的文字。

  2. 從 ContosoOutlookAddIn.dll.manifest 檔案複製介於 <vstav3:entryPointsCollection> 和 </vstav3:entryPointsCollection> 項目之間的文字。 您的程式碼應該看起來如下。

          <vstav3:entryPoints>
            <vstav3:entryPoint
              class="ContosoOutlookAddIn.ThisAddIn">
              <assemblyIdentity
                name="ContosoOutlookAddIn"
                version="1.0.0.0"
                language="neutral"
                processorArchitecture="msil" />
            </vstav3:entryPoint>
          </vstav3:entryPoints>
    
    注意事項注意事項

    如果 Outlook 應用程式層級增益集使用表單區域,則 Outlook 輸入點必須列在 <vstav3:entryPoints> 區段中的最後一個。

  3. 在 ContosoInstaller.dll.manifest 檔案的 <vstav3:entryPointsCollection> 項目之後貼上剛才複製的程式碼。

  4. 將 id 屬性加入至項目 <vstav3:entryPoints> 區別這其他的進入點。

          <vstav3:entryPoints id="ContosoOutlook">
    
  5. 從 ContosoExcelWorkbook.dll.manifest 檔案複製介於 <vstav3:entryPointsCollection> 和 </vstav3:entryPointsCollection> 項目之間的文字。 您的程式碼應該類似下列程式碼。

          <vstav3:entryPoints>
            <vstav3:entryPoint 
              class="ContosoExcelWorkbook.ThisWorkbook">
              <assemblyIdentity
                name="ContosoExcelWorkbook"
                version="1.0.0.0"
                language="neutral"
                processorArchitecture="msil" />
            </vstav3:entryPoint>
            <vstav3:entryPoint
               class="ContosoExcelWorkbook.Sheet1">
              <assemblyIdentity
                name="ContosoExcelWorkbook"
                version="1.0.0.0"
                language="neutral"
                processorArchitecture="msil" />
            </vstav3:entryPoint>
            <vstav3:entryPoint
              class="ContosoExcelWorkbook.Sheet2">
              <assemblyIdentity
                name="ContosoExcelWorkbook"
                version="1.0.0.0"
                language="neutral"
                processorArchitecture="msil" />
            </vstav3:entryPoint>
            <vstav3:entryPoint
              class="ContosoExcelWorkbook.Sheet3">
              <assemblyIdentity
                name="ContosoExcelWorkbook"
                version="1.0.0.0"
                language="neutral"
                processorArchitecture="msil" />
            </vstav3:entryPoint>
          </vstav3:entryPoints>
    
  6. 在 ContosoInstaller.dll.manifest 檔案的 <vstav3:entryPointsCollection> 項目之後貼上剛才複製的程式碼。

  7. 在 <vstav3:entryPoints> 項目中加入 id 屬性,以區分這個進入點與其他進入點。

          <vstav3:entryPoints id="ContosoExcel">
    

Dd465290.collapse_all(zh-tw,VS.110).gif加入組件

修改應用程式資訊清單,以便將 ContosoOutlookAddin 和 ContosoExcelWorkbook 組件載入至 <vstov4> 命名空間。

若要將組件加入至應用程式資訊清單中的 vstov4 命名空間

  1. 在 ContosoInstaller.dll.manifest 檔案中,移除介於 <vstov4:customizations xmlns:vstov4="urn:schemas-microsoft-com:vsto.v4"> 和 </vstov4:customizations> 項目之間的文字。

  2. 從 ContosoOutlookAddIn.dll.manifest 檔案複製介於 <vstov4:customizations xmlns:vstov4="urn:schemas-microsoft-com:vsto.v4"> 和 </vstov4:customizations> 項目之間的文字。 您的程式碼應該看起來與下列範例相同。

            <vstov4:customization>
              <vstov4:appAddIn
                application="Outlook"
                loadBehavior="3"
                keyName="ContosoOutlookAddIn">
                <vstov4:friendlyName>
                  ContosoOutlookAddIn
                </vstov4:friendlyName>
                <vstov4:description>
                  ContosoOutlookAddIn - Outlook add-in created with
                  Visual Studio Tools for Office
                </vstov4:description>
              </vstov4:appAddIn>
            </vstov4:customization>
    
  3. 在 ContosoInstaller.dll.manifest 檔案的 <vstov4:customizations xmlns:vstov4="urn:schemas-microsoft-com:vsto.v4"> 項目之後貼上剛才複製的程式碼。

  4. 在 <vstav3:customization> 項目中加入 id 屬性,以區分這個自訂內容與其他自訂內容。 這個 id 與先前步驟中加入至 <vstav3:entryPoints> 項目的 id 相同。

            <vstov4:customization id="ContosoOutlook">
    
  5. 從 ContosoExcelWorkbook.dll.manifest 檔案複製介於 <vstov4:customizations xmlns:vstov4="urn:schemas-microsoft-com:vsto.v4"> 和 </vstov4:customizations> 項目之間的文字。 您要找的程式碼看起來如下,其中只有 <solutionId> 項目可能會不同:

            <vstov4:customization>
              <vstov4:document
                solutionId="73e" />
            </vstov4:customization>
    
  6. 在 ContosoInstaller.dll.manifest 檔案的 <vstov4:customizations xmlns:vstov4="urn:schemas-microsoft-com:vsto.v4"> 項目之後貼上剛才複製的程式碼。

  7. 在 <vstov4:customizations xmlns:vstov4="urn:schemas-microsoft-com:vsto.v4"> 項目中加入 id 屬性,以區分這個自訂內容與其他自訂內容。 這個 id 與先前步驟中加入至 <vstav3:entryPoints> 項目的 id 相同。

            <vstov4:customization id="ContosoExcel">
    

修改文件層級專案

對於多專案部署中的所有文件層級專案,您必須將 ID 附加至 _AssemblyLocation 自訂文件屬性。 本節示範如何更新 ContosoExcelWorkbook.xlsx 檔案中的 _AssemblyLocation 屬性,這個步驟必須對所有文件層級專案重複執行。

若要在 Excel 或 Word 2010 中修改 _AssemblyLocation

  1. 在 Excel 中,請選取 [檔案] 索引標籤。

  2. 選取 [資訊] 按鈕。

  3. 選取 [屬性] 下拉箭號,然後選取 [進階屬性]。

  4. 選取 [自訂] 索引標籤。

  5. 在 [屬性] 窗格中,選取 [_AssemblyLocation]。

  6. 在 [] 文字方塊中,編輯文字移除 |vstolocal 文字 (如果存在) 並加入 |id=ContosoInstaller。

  7. 選擇 [確定] 按鈕。

重新簽署資訊清單

使用憑證簽署應用程式和部署資訊清單, 以確保檔案未遭修改。

若要重新簽署應用程式和部署資訊清單

  1. 複製 ContosoInstaller_TemporaryKey.pfx 憑證檔從 %USERPROFILE%\Documents\Visual Studio 2012\Projects\ContosoInstaller\ContosoInstaller 方案目錄中 c:\publish\Application Files\ContosoInstaller_1_0_0_0目錄。

  2. 開啟 Visual Studio 命令提示字元。

  3. 切換到 c:\publish\Application Files\ContosoInstaller_1_0_0_0 目錄。

  4. 使用下列命令簽署修改後的應用程式資訊清單:

    mage -sign ContosoInstaller.dll.manifest -certfile ContosoInstaller_TemporaryKey.pfx
    

    「ContosoInstaller.dll.manifest 簽署成功」訊息隨即顯示。

  5. 切換到 c:\publish 目錄。

  6. 使用下列命令更新及簽署修部署資訊清單:

    mage -update ContosoInstaller.vsto -appmanifest "Application Files\ContosoInstaller_1_0_0_0\ContosoInstaller.dll.manifest" -certfile "Application Files\ContosoInstaller_1_0_0_0\ContosoInstaller_TemporaryKey.pfx"
    

    「ContosoInstaller.vsto 簽署成功」訊息隨即顯示。

  7. 將 ContosoInstaller.vsto 檔案複製到 c:\publish\Application Files\ContosoInstaller_1_0_0_0 目錄。

測試多重專案部署

下列程序可確保資訊清單會安裝 Outlook 增益集和 Excel 活頁簿。

若要測試多重專案部署

  1. 將 c:\publish 目錄複製到測試用電腦。

  2. 執行安裝程式以安裝多重專案部署。

    [Microsoft Office 自訂安裝程式] 隨即顯示。

  3. 選取 [安裝]。

    [Microsoft Office 自訂安裝程式] 對話方塊隨即顯示下列訊息:「已成功安裝 Microsoft Office 自訂。」

  4. 開啟 Outlook 以確認增益集可運作。

  5. 開啟 Excel 活頁簿檔案以確認文件層級自訂可運作。

  6. 確認多重專案部署在已安裝之應用程式的清單中具有單一進入點。

    在 Windows XP 中的 [新增/移除程式] 或 Windows Vista 中的 [程式和功能] 會顯示 [ContosoInstaller]。

清除發行目錄

下列程序可從發行目錄移除所有不需要的檔案。

若要清除發行目錄

  1. 從 c:\publish\Application Files\ContosoInstaller_1_0_0_0 目錄移除下列檔案:

    • ContosoExcelWorkbook.dll.manifest

    • ContosoExcelWorkbook.vsto

    • ContosoInstaller.dll.deploy

    • ContosoInstaller.docx

    • ContosoInstaller_TemporaryKey.pfx

    • ContosoOutlookAddIn.dll.manifest

    • ContosoOutlookAddIn.vsto

  2. 從 c:\publish 目錄移除下列檔案:

    • ContosoExcelWorkbook.vsto

    • ContosoInstaller.docx

    • ContosoOutlookAddIn.vsto

請參閱

工作

HOW TO:重新簽署應用程式和部署資訊清單

概念

保護 ClickOnce 應用程式

其他資源

部署 Office 方案