更新(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)”下,原因有两个:
- 因此所有用户都可以访问加载项,并且
- 在 (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 主机)并以管理员身份运行安装程序。
结果
不考虑我在wxs 文件中声明的注册表设置,我的注册表项是在HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Office\Word\AddIns\LesCaveatAddIn 中创建的,即它们按预期进入HKLM,但它们进入\Software\Wow6432Node\Microsoft..... 而不是@ 987654379@ 我在wxs 文件中编码。我认为这是因为我的生产机器是 64 位机器。
正如预期的那样,加载项本身安装在 c:\program files (x86) 下
调出 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>