演练:在 .NET Framework 4 的单个 ClickOnce 安装程序中部署多个 Office 解决方案

更新:2010 年 9 月

您可以将多个 Office 解决方案部署到单个程序包中,以简化安装和更新的过程。 这需要您在发布之后和安装之前,对应用程序清单和部署清单进行修改和重新签名。

**适用于:**本主题中的信息适用于 Microsoft Office 2010 和 2007 Microsoft Office system 的文档级项目和应用程序级项目。有关更多信息,请参见按 Office 应用程序和项目类型提供的功能

本演练阐释了以下任务:

  • 创建两个要部署的 Office 解决方案,其中一个 Office 解决方案为安装程序项目。

  • 修改安装程序项目的应用程序清单,以安装两个 Office 解决方案。

  • 对应用程序清单和部署清单进行重新签名。

提示

对于在以下说明中使用的某些 Visual Studio 用户界面元素,您的计算机可能会显示不同的名称或位置。这些元素取决于您所使用的 Visual Studio 版本和您所使用的设置。有关更多信息,请参见 Visual Studio 设置

系统必备

您需要以下组件来完成本演练:

-

Visual Studio 2010 的一个版本,其中包含 Microsoft Office 开发工具。有关更多信息,请参见[将计算机配置为开发 Office 解决方案](bb398242\(v=vs.100\).md)。
  • Word 2007 或 Word 2010。

  • Outlook 2007 或 Outlook 2010。

  • Excel 2007 或 Excel 2010。

  • 一台测试计算机。

创建多个 Office 解决方案

首先创建三个 Office 项目,其中一个项目为安装程序。 其他两个项目将被部署到最终用户计算机上。

创建和部署新的 Word、Outlook 和 Excel项目

  1. 创建一个以 .NET Framework 4 为目标的 Word 文档级项目。 将项目命名为 ContosoInstaller,并将其保存到 %USERPROFILE%\Documents\Visual Studio 2010\Projects 目录中。

    ContosoInstaller 项目将用作安装程序。 有关更多信息,请参见如何:在 Visual Studio 中创建 Office 项目

  2. 在 ContosoInstaller 解决方案中,添加一个名为 ContosoOutlookAddIn 的 Outlook 应用程序级项目,并向这个 Outlook 项目添加代码。

  3. 在 ContosoInstaller 解决方案中,添加一个名为 ContosoExcelWorkbook 的 Excel 文档级项目,并向这个 Excel 项目添加代码。

发布 Office 解决方案

使用**“发布向导”“项目设计器”“项目页”**将 Office 解决方案发布到开发计算机上。

发布 Word、Outlook 和 Excel 项目

  1. 将 ContosoInstaller 项目发布到 c:\publish 文件夹。 有关更多信息,请参见如何:使用 ClickOnce 部署 Office 解决方案

  2. 将 ContosoOutlookAddIn 项目发布到 c:\publish 文件夹。

  3. 将 ContosoExcelWorkbook 项目发布到 c:\publish 文件夹。

修改应用程序清单

使用 Visual Studio 中的 XML 编辑器向应用程序清单添加安装依赖项、文件、入口点和程序集。 应用程序清单的内容与列出了包装盒中的全部内容的物料单相似;应用程序清单列出了所有依赖程序集和系统必备程序集,以及应用程序需要的文件。 Office 解决方案的应用程序清单还列出了应由应用程序级外接程序和文档级自定义项的 Office 应用程序加载的程序集。

添加安装依赖项

修改应用程序清单,以安装 ContosoOutlookAddin 和 ContosoExcelWorkbook 程序集,并移除对 ContosoInstaller 程序集的引用。

向应用程序清单添加安装依赖项

  1. 从 c:\publish\Application Files 文件夹,将 ContosoOutlookAddIn_1_0_0_0 和 ContosoExcelWorkbook_1_0_0_0 目录的内容移到 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 保留在最终的清单中。

添加入口点

修改应用程序清单,以将 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">
    

添加程序集

修改应用程序清单,以将 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. 单击“确定”。

在 Excel 或 Word 2007 中修改 _AssemblyLocation

  1. 在 Excel 中,单击**“Microsoft Office 按钮”**。

  2. 指向“准备”,然后单击**“属性”**。

  3. 单击**“文档属性”下拉箭头,然后单击“高级属性”**。

  4. 单击**"自定义"**选项卡。

  5. 在**“属性”窗格中,单击“_AssemblyLocation”**。

  6. 在“值”文本框中,编辑文本以移除 |vstolocal(如果存在该文本)并添加 |id=ContosoInstaller。

  7. 单击“确定”。

对清单进行重新签名

使用证书对应用程序和部署清单进行签名。 这可确保文件不被篡改。

对应用程序清单和部署清单进行重新签名

  1. 将 ContosoInstaller_TemporaryKey.pfx 证书文件从 %USERPROFILE%\Documents\Visual Studio 2010\Projects\ContosoInstaller\ContosoInstaller 解决方案目录复制到 c:\publish\Application Files\ContosoInstaller_1_0_0_0目录中。

  2. 打开 Visual Studio 命令提示符。

  3. 转到 the 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

请参见

任务

如何:为应用程序和部署清单重新签名

概念

保护 ClickOnce 应用程序

高级 Office 解决方案部署

其他资源

部署 Office 解决方案

修订记录

日期

修订记录

原因

2010 年 9 月

将 %USERPROFILE%\Documents\Visual Studio 10\Projects 更改为 %USERPROFILE%\Documents\Visual Studio 2010\Projects。

内容 Bug 修复