【问题标题】:How to add net.tcp to the "Enabled protocols" by using a WIX 3.5 project/setup?如何使用 WIX 3.5 项目/设置将 net.tcp 添加到“启用的协议”?
【发布时间】:2011-03-09 14:43:04
【问题描述】:

我们有一些安装 WCF 服务的 MSI 包(由 WIX 生成)。这些服务中的大多数都需要 net.tcp 来进行端点绑定。

我想让我们的部署生活更轻松,并自动化添加 net.tcp 的过程。 我已经知道 WixIisExtension.dll 并利用它的有用功能(创建网站、virt.目录等)。

我可以使用 WixIisExtension 启用 net.tcp 协议吗? 如果没有,我该如何实现?

【问题讨论】:

  • 在官方的 Windows Installer XML Toolset 3.5 文档中,我找不到任何描述如何执行此操作的主题。我会假设使用 IIS 元素(如 WebDirProperties、WebVirtualDir 或 WebApplication)应该是可能的,但没有什么可以引导我走向正确的方向。

标签: wix iis-7.5 wcf-binding wix3.5 net.tcp


【解决方案1】:

您可以查看 MSDN 上的 this article。最后有一节说明了如何使用managed API 来实现配置启用WAS 的服务。我不熟悉 Wix,但您可能可以使用此代码并将其插入到一些自定义部署步骤中。

【讨论】:

    【解决方案2】:

    据我所知,使用标准 WiXIIsExtension 无法做到这一点。因此,您唯一的选择是自定义操作。

    您还可以发现 this thread 很有趣 - 它提供了如何在 MSBuild 脚本中实现类似功能的提示,但您应该能够轻松地将其转换为自定义操作。

    祝你好运!

    【讨论】:

      【解决方案3】:

      将新项目添加到您的安装解决方案(Windows Installer XML -> C# 自定义操作项目)

      在此项目中添加对 Microsoft.Web.Administration 程序集的引用,可在此处找到:C:\Windows\System32\inetsrv 并且需要添加协议。

      我的自定义操作如下所示:

      using System;
      using System.Linq;
      using Microsoft.Deployment.WindowsInstaller;
      using Microsoft.Web.Administration;
      
      namespace Setup.CustomAction.EnableProtocols
      {
          public class CustomActions
          {
              [CustomAction]
              public static ActionResult EnableProtocols(Session session)
              {
                  session.Log("Begin EnableProtocols");
      
                  var siteName = session["SITE"];
                  if (string.IsNullOrEmpty(siteName))
                  {
                      session.Log("Property [SITE] missing");
                      return ActionResult.NotExecuted;
                  }
      
                  var alias = session["VIRTUALDIRECTORYALIAS"];
                  if (string.IsNullOrEmpty(alias))
                  {
                      session.Log("Property [VIRTUALDIRECTORYALIAS] missing");
                      return ActionResult.NotExecuted;
                  }
      
                  var protocols = session["PROTOCOLS"];
                  if (string.IsNullOrEmpty(protocols))
                  {
                      session.Log("Property [PROTOCOLS] missing");
                      return ActionResult.NotExecuted;
                  }
      
                  try
                  {
                      var manager = new ServerManager();
      
                      var site = manager.Sites.FirstOrDefault(x => x.Name.ToUpper() == siteName.ToUpper());
                      if (site == null)
                      {
                          session.Log("Site with name {0} not found", siteName);
                          return ActionResult.NotExecuted;
                      }
      
                      var application = site.Applications.FirstOrDefault(x => x.Path.ToUpper().Contains(alias.ToUpper()));
                      if (application == null)
                      {
                          session.Log("Application with path containing {0} not found", alias);
                          return ActionResult.NotExecuted;
                      }
      
                      application.EnabledProtocols = protocols;
                      manager.CommitChanges();
                      return ActionResult.Success;
                  }
                  catch (Exception exception)
                  {
                      session.Log("Error setting enabled protocols: {0}", exception.ToString());
                      return ActionResult.Failure;
                  }
              }
          }
      }
      

      请注意,我在这里假设三个属性:SITE、VIRTUALDIRECTORYALIAS & PROTOCOLS

      立即构建解决方案。在后台,WiX 创建了两个程序集 %Project%.dll 和 %Project%.CA.dll。 CA.dll 自动包含依赖的 Microsoft.Web.Administration。

      然后在您的 WiX 设置项目中包含对新自定义操作项目的引用。引用 %Projet%.CA.dll 需要该引用。

      编辑product.wxs

      首先在产品元素内的某处添加属性:

      <!-- Properties -->
      <Property Id="SITE" Value="MySite" />
      <Property Id="VIRTUALDIRECTORYALIAS" Value="MyVirtDirectoryAlias" />
      <Property Id="PROTOCOLS" Value="http,net.tcp" />
      

      下面添加二进制元素:

      <!-- Binaries -->
      <Binary Id="CustomAction.EnableProtocols" SourceFile="$(var.Setup.CustomAction.EnableProtocols.TargetDir)Setup.CustomAction.EnableProtocols.CA.dll" />
      

      请注意,您必须添加 CA.dll。

      在下面添加自定义操作:

      <!-- Custom Actions -->
      <CustomAction Id="EnableProtocols" BinaryKey="CustomAction.EnableProtocols" DllEntry="EnableProtocols" Execute="immediate" Return="check" />
      

      最后是您希望执行的安装顺序。

      <!-- Installation Sequence -->
      <InstallExecuteSequence>
        <Custom Action="EnableProtocols" After="InstallFinalize">NOT Installed</Custom>
      </InstallExecuteSequence>
      

      就是这样。应该管用。 感谢 Darin Dimitrov 提供上述链接。

      【讨论】:

      • 很棒的迷你教程。感谢您填写事物之间的关系。特别是“.CA.dll”巫术。
      • 谢谢!我在这里添加了“检查现有”逻辑 ::: Binding foundBinding = site.Bindings.FirstOrDefault(b => b.Protocol.Equals(bindingProtocol, StringComparison.OrdinalIgnoreCase) && b.BindingInformation.Equals(bindingInformation, StringComparison. OrdinalIgnoreCase));
      • if (null == foundBinding) { //// 添加绑定 session.Log("关于添加到 Site.Bindings.SITE='{0}', BINDINGINFORMATION='{1}', BINDINGPROTOCOL='{2}'.", 站点名称, bindingInformation, bindingProtocol); site.Bindings.Add(bindingInformation, bindingProtocol);
      • serverManager.CommitChanges(); session.Log("ServerManager.CommitChanges 添加到 Site.Bindings 成功。SITE='{0}', BINDINGINFORMATION='{1}', BINDINGPROTOCOL='{2}'.", sitename, bindingInformation, bindingProtocol);结果=真; }
      • else { session.Log(string.Format("绑定已经存在。(SiteName='{0}', bindingInformation='{1}', bindingProtocol='{2}')",站点名称、绑定信息、绑定协议));结果=真; /* 如果绑定已经存在,不要失败,关键是要有绑定 */ }
      【解决方案4】:

      这是在 WIX 中执行此操作的正确方法(假设您在 64 位操作系统上安装 - 如果不是猜测,我会说将 CAQuietExec64 更改为 CAQuietExec,尽管这未经测试):

      获取对 appcmd.exe 的引用:

      <Property Id="APPCMD">
        <DirectorySearch Id="FindAppCmd" Depth="1" Path="[WindowsFolder]\system32\inetsrv\">
          <FileSearch Name="appcmd.exe"/>
        </DirectorySearch>
      </Property>
      

      定义以下自定义操作(属性 [WEB_SITE_NAME][WEB_APP_NAME] 可以在安装程序的其他位置填充;或者为了测试您可以对它们进行硬编码):

      <CustomAction
        Id="SetEnableNetTCPCommmand"
        Property="EnableNetTCP"
        Value="&quot;[APPCMD]&quot; set app &quot;[WEB_SITE_NAME]/[WEB_APP_NAME]&quot; /enabledProtocols:http,net.tcp"/>
      
      <CustomAction 
        Id="EnableNetTCP"
        BinaryKey="WixCA"
        DllEntry="CAQuietExec64"
        Execute="deferred"
        Return="ignore"
        Impersonate="no" />
      

      现在在InstallExecuteSequence添加

      <InstallExecuteSequence>
        ...
        <Custom Action="SetEnableNetTCPCommmand" After="InstallExecute">APPCMD AND NOT Installed</Custom>
        <Custom Action="EnableNetTCP" After="SetEnableNetTCPCommmand">APPCMD AND NOT Installed</Custom>
        ...
      </InstallExecuteSequence>
      

      如果一切顺利,现在将更新协议。

      【讨论】:

      • 玩得很好。我正在通过命名管道部署托管在 IIS 中的 WCF 服务。通过一些调整,我现在启用的协议中有“http,net.pipe”。这不在默认的 wix-installer 中令人失望。
      猜你喜欢
      • 2011-11-13
      • 1970-01-01
      • 2014-03-20
      • 2011-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多