您如何使用WiX部署VSTO 3.0插件?

时间:2009-02-10 14:01:32

标签: wix vsto ms-office add-in wix3

我想部署我用Visual Studio 2008编写的VSTO 3应用程序级Word 2007插件。我看到WiX有一个名为WixOfficeExtension的扩展,看起来它可能具有此功能,但我找不到任何它的文档,我无法从源代码中辨别它的目的。

之前是否有人尝试过此操作,您是否能够成功将其拉下来?

2 个答案:

答案 0 :(得分:21)

这是我最终使用的代码。我基本上将MSDN中的示例移植到了使用WiX。

注意:此特定解决方案仅适用于Word 2007插件,但Excel的情况非常相似。只需根据前面提到的MSDN Article修改注册表/组件检查和键/值。

包含列表自定义操作

要以完全信任的方式运行插件,必须将其添加到当前用户的包含列表中。可靠地执行此操作的唯一方法是使用自定义操作。这是WiX附带的新article Deployment Tools Foundation中自定义操作的端口。

要使用它,请创建一个名为VSTOCustomAction的新DTF项目并添加CustomAction.cs。

CustomAction.cs
using 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 Fragment

我们显然需要实际的WiX文件来安装插件。使用

从主.wcs文件中引用它
<FeatureRef Id="MyAddinComponent"/>
Addin.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>

希望这可以节省一些人的时间。

答案 1 :(得分:8)

我很惊讶没有人回答这个问题......我一直在研究Addins,所以我只想在这里转一些链接。我不确定你是否已经找到了你正在寻找的解决方案,但这可以帮助其他像我这样的搜索:

答案是安装vsto 3.0 addins for office确实适用于wix,但我对这个WixOfficeExtension一无所知?对我而言,让它工作并不是一项简单的任务,你需要做很多事情来正确完成这项任务:

步骤1.我真的想使用VSTO吗?

见这里:http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/3f97705a-6052-4296-a10a-bfa3a39ab4e7/#)http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/3f97705a-6052-4296-a10a-bfa3a39ab4e7/#

步骤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

到这里查找提示/想法的完美摘要。我也在这里浏览论坛寻求帮助,这是一个非常好的网站。(很好地总结,适用于展望但适用于办公室):http://www.outlookcode.com/article.aspx?ID=42

步骤4. Wix

A)熟悉这一点,您需要它:应用程序级外接程序的注册表项 http://msdn.microsoft.com/en-us/library/bb386106.aspx#

B)使用Visual Studio中Windows安装程序的安装对象生成MSI文件。

C)测试msi并确保你的插件使用微软MSI。请相信我,许多问题会带给你最多的时间。

D)运行dark.exe(在wix bin中)并查看为输出文件创建的注册表设置。

E)将这些注册表设置添加到您的wix文件中 - 我确实觉得这个博客有点帮助,但它适用于Excel的com插件:http://matthewrowan.spaces.live.com/blog/cns!CCB05A30BCA0FF01!143.entry

F)运行并部署。

注意:我会在这里添加更多,因为我在这里找到更多。我还在学习Wix以及我可以用插件等方面做些什么.Wix很棒,Office插件的部署是一种巨大的痛苦。

相关问题