【问题标题】:How do you use WiX to deploy VSTO 3.0 addins?如何使用 WiX 部署 VSTO 3.0 插件?
【发布时间】:2016-01-13 18:14:08
【问题描述】:

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

以前有没有人尝试过,你能成功吗?

【问题讨论】:

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


    【解决方案1】:

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

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

    包含列表自定义操作

    为了以完全信任的方式运行插件,必须将其添加到当前用户的包含列表中。可靠地做到这一点的唯一方法是使用自定义操作。这是将 article 中的自定义操作移植到 WiX 中包含的新 Deployment Tools Foundation

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

    自定义动作.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 文件来安装插件。从你的主 .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>
    

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

    【讨论】:

    • PropertyAssign_ManifestLocation 也应在“RemoveFromInclusionList”之前进行评估,否则重大升级将失败。
    • 值得注意的是,在构建外接程序项目成功后,可以在.dll.manifest 文件中找到RSAKeyValue 块。我花了很长时间才弄清楚那是哪里。
    【解决方案2】:

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

    答案是为办公室安装 vsto 3.0 插件确实适用于 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 步。打蜡

    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 插件部署是一件非常痛苦的事情。

    【讨论】:

    • 我确实成功地完成了这项工作,一旦时间允许,将发布答案......
    • 非常好。我希望这对其他人有所帮助,因为 wix 并不是最容易使用插件的。我实际上一直在研究 COM 插件,但也测试了 VSTO。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-12
    • 1970-01-01
    • 1970-01-01
    • 2013-05-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多