代码之家  ›  专栏  ›  技术社区  ›  Jacob

如何使用WiX将VSTO部署到3.0加载项?

  •  20
  • Jacob  · 技术社区  · 15 年前

    2 回复  |  直到 9 年前
        1
  •  21
  •   Jacob    15 年前

    这就是我最终使用的代码。我基本上移植了 MSDN 使用WiX。

    注: MSDN Article .

    包含列表自定义操作

    article Deployment Tools Foundation 包含在WiX中。

    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文件来安装插件。使用从主.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>
    

    希望这能为其他人节省一些时间。

        2
  •  8
  •   Brian    15 年前

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

    答案是为office安装vsto 3.0加载项确实适用于wix,但我对WixOffice扩展一无所知?对我来说,让它工作并不是一项简单的任务,你需要做很多事情才能正确完成这项任务:

    请看这里: 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/#

    http://blogs.msdn.com/mshneer/archive/2006/01/05/deployment-articles.aspx Microsoft部署信息在此: http://msdn.microsoft.com/en-us/library/bb386179.aspx#

    第三步。我是否需要一次安装多个加载项,还是因为需要而使用WIX? 转至步骤4。

    如果您不使用visual studio中的安装程序并使您的生活变得轻松。。。 这是Microsofts安装程序,最简单的方法: http://msdn.microsoft.com/en-us/library/cc563937.aspx

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

    第四步。巫师

    A) 熟悉这一点您需要它: http://msdn.microsoft.com/en-us/library/bb386106.aspx#

    C) 测试该msi并确保加载项使用microsoft msi工作。相信我,很多问题让你在这里花的时间最多。

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

    E) 将这些注册表设置添加到wix文件中。
    http://matthewrowan.spaces.live.com/blog/cns!CCB05A30BCA0FF01!143.entry

    F) 运行并部署。