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

Jac*_*cob 20 vsto add-in wix wix3 ms-office

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

有没有人试过这个,你能成功地把它拉下来吗?

Jac*_*cob 21

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

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

包含列表自定义操作

要以完全信任方式运行插件,必须将其添加到当前用户的包含列表中.可靠地执行此操作的唯一方法是使用自定义操作.这是WiX附带的新部署工具基础文章中自定义操作的一个端口.

要使用它,请创建一个名为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;
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

Wix片段

我们显然需要实际的WiX文件来安装插件.用你的主.wcs文件引用它

<FeatureRef Id="MyAddinComponent"/>
Run Code Online (Sandbox Code Playgroud) 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>
Run Code Online (Sandbox Code Playgroud)

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


Bri*_*ian 8

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

答案是安装vsto 3.0 addins办公室确实适用于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 /线程/ 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!1433.entry

F)运行和部署.

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