我想部署我用 Visual Studio 2008 编写的 VSTO 3 Application Level Word 2007 插件。我看到 WiX 有一个名为 WixOfficeExtension 的扩展,看起来它可能具有此功能,但我找不到任何文档,我无法从源代码中辨别出它的目的。
以前有没有人尝试过这个,你能成功地完成它吗?
这是我最终使用的代码。我基本上将示例从MSDN移植到使用 WiX。
注意:此特定解决方案仅适用于 Word 2007 插件,但 Excel 的情况非常相似。只需根据上述MSDN 文章修改注册表/组件检查和键/值。
为了以完全信任的方式运行插件,必须将其添加到当前用户的包含列表中。可靠地做到这一点的唯一方法是使用自定义操作。这是文章中的自定义操作移植到WiX 中包含的新部署工具基础。
要使用它,请创建一个名为 VSTOCustomAction 的新 DTF 项目并添加 CustomAction.cs。
自定义动作.csusing System;
using System.Security;
using System.Security.Permissions;
using Microsoft.Deployment.WindowsInstaller;
using Microsoft.VisualStudio.Tools.Office.Runtime.Security;
namespace VSTOCustomActions
{
public class CustomActions
{
private static string GetPublicKey(Session session)
{
return session["VSTOCustomAction_PublicKey"];
}
private static string GetManifestLocation(Session session)
{
return session["VSTOCustomAction_ManifestLocation"];
}
private static void ErrorMessage(string message, Session session)
{
using (Record r = new Record(message))
{
session.Message(InstallMessage.Error, r);
}
}
[CustomAction]
public static ActionResult AddToInclusionList(Session session)
{
try
{
SecurityPermission permission =
new SecurityPermission(PermissionState.Unrestricted);
permission.Demand();
}
catch (SecurityException)
{
ErrorMessage("You have insufficient privileges to " +
"register a trust relationship. Start Excel " +
"and confirm the trust dialog to run the addin.", session);
return ActionResult.Failure;
}
Uri deploymentManifestLocation = null;
if (Uri.TryCreate(GetManifestLocation(session),
UriKind.RelativeOrAbsolute, out deploymentManifestLocation) == false)
{
ErrorMessage("The location of the deployment manifest is missing or invalid.", session);
return ActionResult.Failure;
}
AddInSecurityEntry entry = new AddInSecurityEntry(deploymentManifestLocation, GetPublicKey(session));
UserInclusionList.Add(entry);
session.CustomActionData.Add("VSTOCustomAction_ManifestLocation", deploymentManifestLocation.ToString());
return ActionResult.Success;
}
[CustomAction]
public static ActionResult RemoveFromInclusionList(Session session)
{
string uriString = session.CustomActionData["VSTOCustomAction_ManifestLocation"];
if (!string.IsNullOrEmpty(uriString))
{
Uri deploymentManifestLocation = new Uri(uriString);
UserInclusionList.Remove(deploymentManifestLocation);
}
return ActionResult.Success;
}
}
}
我们显然需要实际的 WiX 文件来安装插件。从您的主 .wcs 文件中引用它
<FeatureRef Id="MyAddinComponent"/>
插件.wcs
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment Id="Word2007Fragment">
<!-- Include the VSTO Custom action -->
<Binary Id="VSTOCustomAction" SourceFile="path\to\VSTOCustomAction.dll"/>
<CustomAction Id="AddToInclusionList" BinaryKey="VSTOCustomAction" DllEntry="AddToInclusionList" Execute="immediate"/>
<CustomAction Id="RemoveFromInclusionList" BinaryKey="VSTOCustomAction" DllEntry="RemoveFromInclusionList" Execute="immediate"/>
<!-- Set the parameters read by the Custom action -->
<!--
The public key that you used to sign your dll, looks something like <RSAKeyValue><Modulus>...</Modulus><Exponent>...</Exponent></RSAKeyValue>
Take note: There should be no whitespace in the key!
-->
<Property Id="VSTOCustomAction_PublicKey"><![CDATA[Paste you public key here]]></Property>
<CustomAction Id="PropertyAssign_ManifestLocation" Property="VSTOCustomAction_ManifestLocation" Value="[INSTALLDIR]MyAddin.MyAddin.vsto" />
<!-- Properties to check prerequisites -->
<Property Id="VSTORUNTIME">
<RegistrySearch Id="RegistrySearchVsto"
Root="HKLM"
Key="SOFTWARE\Microsoft\vsto runtime Setup\v9.0.30729"
Name="SP"
Type="raw"/>
</Property>
<Property Id="HASWORDPIA">
<ComponentSearch Id="ComponentSearchWordPIA"
Guid="{816D4DFD-FF7B-4C16-8943-EEB07DF989CB}"/>
</Property>
<Property Id="HASSHAREDPIA">
<ComponentSearch Id="ComponentSearchSharedPIA"
Guid="{FAB10E66-B22C-4274-8647-7CA1BA5EF30F}"/>
</Property>
<!-- Feature and component to include the necessary files -->
<Feature Id="MyAddinComponent" Title ="Word 2007 Addin" Level="1" AllowAdvertise="no">
<ComponentRef Id="MyAddinComponent"/>
<Condition Level="0"><![CDATA[NOT ((VSTORUNTIME="#1") AND HASSHAREDPIA AND HASWORDPIA)]]></Condition>
</Feature>
<DirectoryRef Id="INSTALLDIR">
<Component Id="MyAddinComponent" Guid="your component guid here">
<File Name="MyAddin.dll" Source="path\to\MyAddin.dll" />
<File Name="MyAddin.dll.manifest" Source="path\to\MyAddin.dll.manifest" />
<File Name="MyAddin.vsto" Source="path\to\MyAddin.vsto" />
<RegistryKey Root="HKCU"
Key="Software\Microsoft\Office\Word\Addins\MyAddin"
Action="createAndRemoveOnUninstall">
<RegistryValue Type="string" Name="FriendlyName" Value="MyAddin Word 2007 Addin" />
<RegistryValue Type="string" Name="Description" Value="MyAddin Word 2007 Addin" />
<RegistryValue Type="string" Name="Manifest" Value="[INSTALLDIR]MyAddin.vsto|vstolocal" KeyPath="yes"/>
<RegistryValue Type="integer" Name="LoadBehavior" Value="3"/>
</RegistryKey>
</Component>
</DirectoryRef>
<!-- Modify the install sequence to call our custom action -->
<InstallExecuteSequence>
<Custom Action="AddToInclusionList" After="InstallFinalize"><![CDATA[(&MyAddinComponent = 3) AND NOT (!MyAddinComponent = 3)]]></Custom>
<Custom Action="PropertyAssign_ManifestLocation" Before="AddToInclusionList"><![CDATA[(&MyAddinComponent = 3) AND NOT (!MyAddinComponent = 3)]]></Custom>
<Custom Action="RemoveFromInclusionList" After="InstallFinalize"><![CDATA[(&MyAddinComponent = 2) AND NOT (!MyAddinComponent = 2)]]></Custom>
</InstallExecuteSequence>
</Fragment>
</Wix>
希望这可以为外面的人节省一些时间。
我很惊讶没有人回答这个问题......我一直在研究插件,所以我将在这里转储一些链接。我不确定你是否已经找到了你正在寻找的解决方案,但这可以帮助像我一样搜索的其他人:
答案是为办公室安装 vsto 3.0 插件确实适用于 wix,但我对这个 WixOfficeExtension 一无所知?对我来说,让它工作并不是一项简单的任务,你需要做很多事情才能正确完成它:
第 1 步:我真的要使用 VSTO 吗?
步骤 2. 好的 VSTO 在这里是正确的:
来自 MS Misha Shneerson——为 2007 年部署 VSTO:http: //blogs.msdn.com/mshneer/archive/2006/01/05/deployment-articles.aspx此处的 Microsoft 部署信息:http: //msdn.microsoft.com /en-us/library/bb386179.aspx#
第 3 步。我是否需要一次安装多个插件或想要使用 WIX,因为我想要它?转到第 4 步。
如果不使用 Visual Studio 中的安装程序,让您的生活变得轻松......这是微软的安装程序,最简单的方法:http: //msdn.microsoft.com/en-us/library/cc563937.aspx
去这里找到一个很好的提示/想法总结。我也在这里浏览论坛寻求帮助,非常好的网站。(总结得很好,适合 Outlook 但适用于办公室):http ://www.outlookcode.com/article.aspx?ID=42
步骤 4. 打蜡
A)熟悉这个你需要它:应用程序级加载项的注册表项 http://msdn.microsoft.com/en-us/library/bb386106.aspx#
B) 使用 Visual Studio 中基于 Windows 安装程序的设置对象生成 MSI 文件。
C)测试该 msi 并确保您的插件使用 microsoft MSI 工作。相信我,很多问题都会让你花最多的时间在这里。
D) 运行 dark.exe(在 wix bin 中)并查看为输出文件创建的注册表设置。
E)将这些注册表设置添加到您的 wix 文件中。
--我确实发现这个博客有点帮助,但它是针对 Excel 的 com 插件:http://matthewrowan.spaces.live.com/blog/cns!CCB05A30BCA0FF01! 143.entry
F) 运行和部署。
注意:我会在这里添加更多,因为我在这里找到更多。我仍在学习 Wix 以及在插件等方面我可以用它做什么。Wix 很棒,Office 插件部署是一种皇家痛苦。