【问题标题】:How do you package a VSTO Word addin for deployment (to Office 32 bit) using WIX?如何使用 WIX 打包 VSTO Word 插件以进行部署(到 Office 32 位)?
【发布时间】:2019-04-23 16:22:24
【问题描述】:

我在 VS 2017 Pro 中开发了一个 VSTO Word add in。工作正常,准备部署。但是,我找不到打包我的VSTOWordadd in 以在我的开发机器以外的机器上使用的工作程序。对于任何特定的机器,我需要部署一次,并让任何可能使用他们的帐户登录的用户都可以使用它。

第一次遇到 this,但它涉及使用 InstallShield Limited Edition,显然 VS 2017 不再提供该版本。

试过this,但它的一些步骤似乎缺少部分或说“do x”而不解释如何。

尝试了“InnoSetup”和“bovendor/VstoAddinInstaller”,但遵循“bovendor”过程会导致“Innosetup”编译器抛出错误(bovender-dictated 节缺少必需的元素)。无法得到 bovendor 的回复。

搜索了Microsoft docs,但找不到程序。谁能提供打包 VSTO Word 插件以进行部署的过程?

更新 使用 WiX 工具集成功打包并部署了我的加载项。请看下面我的回答

【问题讨论】:

    标签: ms-word wix vsto add-in setup-deployment


    【解决方案1】:

    更新(2019 年 11 月 26 日):如果您的设置使用 64 位 Office,请参阅 How do you package a VSTO Word addin for deployment to a 64-bit Windows 10 machine running Microsoft Office 64 bit using WIX?

    使用WiX工具集成功打包并部署了我的add-in

    学分:我在Add-in Express Blog 上使用Pieter van der Westhuizen's example 学到了大部分内容。

    我在我的开发机器(64 位)上使用了Visual Studio Pro 2017、.NET 4.6.1 和C# 来实现我的VSTOWord 插件。

    我的要求是将add-in 部署到 64 位生产机器(即 Citrix 虚拟桌面主映像),以便任何登录生产机器(即登录虚拟基于主映像的桌面)。主映像上安装了 32 位版本的 Word 2013。

    据我了解,这意味着“插件”必须安装在“C:\Program Files (x86)”下,原因有两个:

    1. 因此所有用户都可以访问加载项,并且
    2. 在 (x86) 下,因为它是 Word 的 32 位版本。

    此外,由于所有用户都需要访问add-in,因此所需的VSTO 注册表项设置位于根HKLM(而不是HKCU)下。本质上,这种“所有用户”设置与“一个用户”Click-Once 设置相反。顺便说一句,我在一个没有连接到互联网的飞地中。所以,我使用的所有软件都是在别处下载,然后携带到 enclave 并安装在本地。

    我的VSTO word 插件(即C:\....\Visual Studio 2017\Projects\FooAddIn\FooAddIn\bin\Release)的发布文件是:

    • FooAddIn.dll
    • FooAddIn.dll.manifest
    • FooAddIn.vsto
    • Microsoft.Office.Tools.Common.v4.0.Utilities.dll

    我做了什么

    • 从http://wixtoolset.org/releases/ 下载并安装了“WiX”v3.11.1 到我的开发机器上。

    • 从https://marketplace.visualstudio.com/items?itemName=RobMensching.WixToolsetVisualStudio2017Extension下载并安装“Wix Toolset Visual Studio 2017 Extension”到我的开发机器上

    • 使用VS 2017 和Solution Explorer 打开我的add-in 项目FooAddIn,鼠标右键单击顶行Solution 节点并单击Add -> New Project。

    • 在Add New Project 对话框中,单击WiX Toolset 下的v3,然后单击Setup Project for WiX v3。我将新项目命名为FooAddInSetup。 Visual Studio Solution Explorer 显示 Solution FooAddIn (2 projects)、项目 FooAddIn 和项目 FooAddInSetup。

    • 在FooAddInSetup -> References 下,添加了对C:\Program Files (x86)\WiX Toolset v3.11\bin\WixNetFxExtension.dll 和C:\Program Files (x86)\WiX Toolset v3.11\bin\WixUIExtension.dll 的引用(Product.wxs 文件的元素需要这些引用来构建安装程序)。

    • 配置 VS 以构建安装程序:在 VS 中,单击构建 -> 配置管理器。在“配置管理器”对话框中,选中 FooAddInSetup 的 Build 复选框。

    • 创建EULA.rtf(我说“这是免许可软件”)并将其放置在 C:....\Visual Studio 2017\Projects\FooAddIn\FooAddInSetup

    • 为我的VSTO 发布文件的位置路径创建了一个预处理器变量:在解决方案资源管理器中,右键单击FooAddInSetup -> Properties。在 FooAddInSetup 选项卡上,单击“构建”。在General 部分,单击Define 'Debug' preprocessor variable。在Define preprocessor variables: 文本框中,输入AddinFiles=..\FooAddIn\bin\$(Configuration)\

    • 为我的add-in 填充了样板文件WiX Product.wxs ,如下所示Product.wxs 文件

    • 注意:在wxs 文件中,我修改了Condition 元素中的Visual Studio 2010 Tools for Office Runtime 超链接 - Pieter 示例中的超链接已失效。

    • 我将解决方案配置设置为 Release 并构建了解决方案。

    • 将FooAddInSetup.msi 从我的开发机器上的...\FooAddInSetup\bin\release 复制到我的生产机器(VDI 主机)并以管理员身份运行安装程序。

    结果

    1. 不考虑我在wxs 文件中声明的注册表设置,我的注册表项是在HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Office\Word\AddIns\LesCaveatAddIn 中创建的,即它们按预期进入HKLM,但它们进入\Software\Wow6432Node\Microsoft..... 而不是@ 987654379@ 我在wxs 文件中编码。我认为这是因为我的生产机器是 64 位机器。

    2. 正如预期的那样,加载项本身安装在 c:\program files (x86) 下

    3. 调出 Word,加载项按预期加载

    Product.wxs 文件

    <?xml version="1.0" encoding="UTF-8"?>
    <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:netfx="http://schemas.microsoft.com/wix/NetFxExtension">
    
      <!--
      The boilerplate Product.wxs file already contains the minimum amount of elements needed to build a WiX installer. 
      If the Product element, Id attribute is set to an asterisk (*), WiX will generate a new GUID every time the setup project is compiled (I left it as-is). 
      Change the Name attribute value and Manufacturer attribute value to values of your choice.
      -->
      <Product Id="*"
               Name="FOO Add-In"
               Language="1033"
               Version="1.0.0.0"
               Manufacturer="Foo Masters"
               UpgradeCode="4b35cc09-4780-4644-a7d4-f5901f7a7e45">
    
        <!--Attributes shown are the minimum number needed to build the setup project.-->
        <Package InstallerVersion="200"
                 Compressed="yes"
                 InstallScope="perMachine" />
    
        <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    
        <!-- Verify if VSTO Office Runtime is installed -->
        <Property Id="VSTORUNTIMEREDIST">
          <RegistrySearch
            Id="VSTORuntimeRedist"
            Root="HKLM"
            Key="SOFTWARE\Microsoft\VSTO Runtime Setup\v4R"
            Name="Version"
            Type="raw" />
        </Property>
    
        <Condition
          Message="The Visual Studio 2010 Tools for Office Runtime is not installed. 
      Please download and install from https://www.microsoft.com/en-us/download/details.aspx?id=48217.">
          <![CDATA[Installed OR VSTORUNTIMEREDIST>="10.0.30319"]]>
        </Condition>
    
        <!-- Verify if .NET Framework is installed -->
        <PropertyRef Id="NETFRAMEWORK40FULL"/>
        <Condition Message="This application requires .NET Framework 4.0.">
          <![CDATA[Installed OR NETFRAMEWORK40FULL]]>
        </Condition>
    
        <!--I want one Cab file, so only one Media element is needed. Make sure the EmbedCab attribute value is "yes".-->
        <Media Id="1" Cabinet="FooAddin.cab" EmbedCab="yes"/>
    
        <!--Set values for display on setup progeam UI-->
        <Feature Id="ProductFeature" Title="FOO Add-In" Level="1">
          <ComponentGroupRef Id="ProductComponents" />
          <ComponentRef Id="Registry_FriendlyName" />
          <ComponentRef Id="Registry_Description" />
          <ComponentRef Id="Registry_Manifest" />
          <ComponentRef Id="Registry_LoadBehavior" />
        </Feature>
    
        <!--Specify that the WiXUI_Minimal UI should be used, i.e, the simplest UI available -->
        <UIRef Id="WixUI_Minimal" />
    
        <!--Specify the EULA file to use-->
        <WixVariable Id="WixUILicenseRtf" Value="EULA.rtf" />
    
      </Product>
    
      <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
          <Directory Id="ProgramFilesFolder">
            <Directory Id="INSTALLFOLDER" Name="FooAddin" />
    
            <!-- Add required VSTO registry entries for 32-bit Word -->
            <!-- see https://docs.microsoft.com/en-us/visualstudio/vsto/registry-entries-for-vsto-add-ins?view=vs-2019-->
    
            <Component Id="Registry_FriendlyName">
              <RegistryValue Id="RegKey_FriendlyName" Root="HKLM"
                             Key="Software\Microsoft\Office\Word\AddIns\FooAddin"
                             Name="FriendlyName"
                             Value="FOO Add-In"
                             Type="string" KeyPath="yes" />
            </Component>
            <Component Id="Registry_Description">
              <RegistryValue Id="RegKey_Description" Root="HKLM"
                             Key="Software\Microsoft\Office\Word\AddIns\FooAddin"
                             Name="Description"
                             Value="FOO Add-In"
                             Type="string" KeyPath="yes" />
            </Component>
            <Component Id="Registry_Manifest">
              <RegistryValue Id="RegKey_Manifest" Root="HKLM"
                             Key="Software\Microsoft\Office\Word\AddIns\FooAddin"
                             Name="Manifest" Value="[INSTALLFOLDER]FooAddin.vsto|vstolocal"
                             Type="string" KeyPath="yes" />
            </Component>
            <Component Id="Registry_LoadBehavior">
              <RegistryValue Id="RegKey_LoadBehavior" Root="HKLM"
                             Key="Software\Microsoft\Office\Word\AddIns\FooAddin"
                             Name="LoadBehavior" Value="3"
                             Type="integer" KeyPath="yes" />
            </Component>
    
          </Directory>
        </Directory>
      </Fragment>
    
      <Fragment>
    
        <!-- Add refs to the components of the VSTO-->
    
        <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
    
          <Component Id="MSOfficeToolsCommon_dll_Component">
            <File Id="MSOfficeToolsCommon_dll" KeyPath="yes"
              Name="Microsoft.Office.Tools.Common.v4.0.Utilities.dll"
              Source="$(var.AddinFiles)"></File>
          </Component>
    
          <Component Id="FooAddin_dll_Component" >
            <File Id="FooAddin_dll" KeyPath="yes"
                  Name="FooAddin.dll"
                  Source="$(var.AddinFiles)" />
          </Component>
    
          <Component Id="FooAddin_vsto_Component">
            <File Id="FooAddin_vsto" KeyPath="yes"
              Name="FooAddin.vsto"
              Source="$(var.AddinFiles)"></File>
          </Component>
    
          <Component Id="FooAddin_dll_manifest_Component">
            <File Id="FooAddin_dll_manifest" KeyPath="yes"
              Name="FooAddin.dll.manifest"
              Source="$(var.AddinFiles)"></File>
          </Component>
    
        </ComponentGroup>
      </Fragment>
    </Wix>
    

    【讨论】:

    • 非常有帮助。感谢您分享您的知识,并为我们提供了一个很好的分步说明。
    【解决方案2】:

    我通常在 Visual Studio 中使用Click-Once deployment。您可以将其部署到网络路径,以便其他用户能够安装它。

    首先您要为 Visual Studio 项目创建一个不过期的证书

    在开始菜单搜索中输入Developer Command并右键单击并选择以管理员身份运行

    在MakeCert 和pvk2pfx 的命令提示符中粘贴以下命令

    MakeCert /n "CN=Your New Cert" /r /h 0 /eku "1.3.6.1.5.5.7.3.3,1.3.6.1.4.1.311.10.3.13" /e "01/01/2100" /sv MyNewCert.pvk MyNewCert.cer 
    pvk2pfx -pvk MyNewCert.pvk -spc MyNewCert.cer -pfx MyNewCert.pfx
    

    注意:

    • 日期格式为美国标准MM/DD/YYYY
    • -f 参数可用于 pvk2pfx 行的末尾以覆盖现有文件
    • 系统会提示您创建密码(这是可选的)

    密码提示后,您只需按 Enter 键即可运行第二个命令行。

    现在您可以为多个 Visual Studio 项目选择相同的证书

    在 Visual Studio 项目属性中,选择 Signing* 点击 Select from File…。 从命令提示符导航到相同的路径并选择证书文件 (*.pfx)

    发布项目

    然后转到项目属性中的发布选项卡并单击立即发布。它将在发布的位置创建一个可执行文件。然后,您只需将指向 .exe 文件的链接发送给您的最终用户。

    【讨论】:

    • 感谢您提供的详细信息,但 Click-Once 不会为我执行此操作,因为据我了解,当您希望单个用户安装 add-在一台机器上只为他们的登录。我需要安装它,以便所有可能登录机器的用户都可以使用 VSTO 加载项。 See Register VSTO Add-ins for the current user vs. all users at this location for implementation details。我现在正在看 WIX。我想也许它会做到。
    • 是的,你是对的,点击一次是每个用户。我有兴趣查看您为机器上的所有用户安装的解决方案。如果它对你有帮助,这里有一堆我在GitHub 上的 VSTO 项目
    • 在下面查看我的答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-03
    • 2013-05-19
    • 1970-01-01
    • 2016-11-14
    • 2012-05-31
    相关资源
    最近更新 更多