更新(2019 年 11 月 26 日):如果您的设置使用 64 位 Office,请参阅如何使用 WIX 打包 VSTO Word 插件以部署到运行 Microsoft Office 64 位的 64 位 Windows 10 计算机? https://stackoverflow.com/questions/58629128/how-do-you-package-a-vsto-word-addin-for-deployment-to-a-64-bit-windows-10-machi
成功打包并部署我的add-in
使用WiX
工具组
信用:我学到了大部分内容Pieter van der Westhuizen 的例子 https://www.add-in-express.com/creating-addins-blog/2012/11/13/wix-installation-vsto-office-addin/ on the 插件 Express 博客 https://www.add-in-express.com/creating-addins-blog/.
I used Visual Studio Pro 2017
, .NET 4.6.1
, and C#
在我的开发机器(64位)上实现我的VSTO
Word
add-in.
我的要求是部署add-in
一次到 64 位生产计算机(即 Citrix 虚拟桌面主映像),因此登录到生产计算机的任何用户都可以使用它(即登录到基于主映像的虚拟桌面)。 32 位版本的 Word 2013 安装在主映像上。
据我了解,这意味着“加载项”必须安装在“C:\Program Files (x86)”下,原因有两个:
- 因此所有用户都可以访问该加载项,并且
- 在 (x86) 下,因为它是 Word 的 32 位版本)。
此外,由于所有用户都需要访问add-in
, 所需VSTO
注册表项设置位于根目录下HKLM
(并不是HKCU
)。本质上,这种“所有用户”设置与“一个用户”设置相反Click-Once
设置。毫无疑问,我处于一个未连接到互联网的飞地。所以,我使用的所有软件都是从其他地方下载的,然后携带到飞地并在本地安装。
我的发布文件VSTO
单词插件(即,在C:\....\Visual Studio 2017\Projects\FooAddIn\FooAddIn\bin\Release
) are:
- FooAddIn.dll
- FooAddIn.dll.manifest
- FooAddIn.vsto
- Microsoft.Office.Tools.Common.v4.0.Utilities.dll
我做了什么
从以下位置下载“WiX”v3.11.1 并将其安装到我的开发机器上http://wixtoolset.org/releases/ http://wixtoolset.org/releases/.
从以下位置将“Wix Toolset Visual Studio 2017 Extension”下载并安装到我的开发计算机上https://marketplace.visualstudio.com/items?itemName=RobMensching.WixToolsetVisualStudio2017Extension https://marketplace.visualstudio.com/items?itemName=RobMensching.WixToolsetVisualStudio2017Extension
打开我的add-in
项目FooAddIn
using VS 2017
and in Solution Explorer
, 鼠标右键单击顶行Solution
节点并单击Add -> New Project
.
In the Add New Project
对话框,点击v3
under WiX Toolset
然后点击Setup Project for WiX v3
。我将新项目命名为FooAddInSetup
。视觉工作室Solution Explorer
shows Solution FooAddIn (2 projects)
, 项目FooAddIn
,以及项目FooAddInSetup
.
Under FooAddInSetup -> References
,添加了对C:\Program Files (x86)\WiX Toolset v3.11\bin\WixNetFxExtension.dll
and C:\Program Files (x86)\WiX Toolset v3.11\bin\WixUIExtension.dll
(Product.wxs 文件的元素需要这些来构建安装程序)。
配置 VS 来构建安装程序:在 VS 中,单击“构建”->“配置管理器”。在配置管理器对话框中,选中Build
FooAddInSetup 的复选框。
Created EULA.rtf
(我的说“这是免许可软件”)并将其放置在 C:....\Visual Studio 2017\Projects\FooAddIn\FooAddInSetup 中
为我的位置的路径创建了一个预处理器变量VSTO
发布文件:在解决方案资源管理器中,单击鼠标右键FooAddInSetup -> Properties
。在 FooAddInSetup 选项卡上,单击“Build”。在里面General
部分,点击Define 'Debug' preprocessor variable
。在里面Define preprocessor variables:
文本框,输入AddinFiles=..\FooAddIn\bin\$(Configuration)\
填充样板WiX
Product.wxs
为我的文件add-in
如下图所示产品.wxs 文件
注:在wxs
文件,我修改了Visual Studio 2010 Tools for Office Runtime
中的超链接Condition
元素 - 彼得例子中的元素已经死了。
我将解决方案配置设置为Release
并构建了解决方案。
Copied FooAddInSetup.msi
from ...\FooAddInSetup\bin\release
在我的开发机器上连接到我的生产机器(VDI master)并以管理员身份运行安装程序。
Results
不考虑我在中声明的注册表设置wxs
文件,我的注册表项是在HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Office\Word\AddIns\LesCaveatAddIn
,即,他们按预期进入了 HKLM,但他们进入了\Software\Wow6432Node\Microsoft.....
代替\Software\Microsoft....
正如我在wxs
文件。我认为这是因为我的生产机器是 64 位机器。
正如预期的那样,加载项本身安装在 c:\program files (x86) 下
启动 Word,加载项已按预期加载
产品.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://learn.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>