问题 如何使用WIX 3.5项目/设置将net.tcp添加到“启用的协议”?


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

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

我可以使用WixIisExtension来启用net.tcp协议吗? 如果没有,我怎么能实现呢?


4339
2018-06-29 12:40


起源

在官方Windows Installer XML Toolset 3.5文档中,我找不到任何描述如何执行此操作的主题。我原以为应该可以使用IIS元素(如WebDirProperties,WebVirtualDir或WebApplication),但没有任何东西可以引导我进入正确的方向。 - DotNetter


答案:


将新项目添加到安装解决方案(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

首先在product元素中的某处添加属性:

<!-- 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提供上述链接。


7
2018-06-21 14:52



很棒的迷你教程。感谢您填写相关内容。 Esp“.CA.dll”伏都教。 - granadaCoder
谢谢!我在这里添加了一个“检查现有”逻辑::: Binding foundBinding = site.Bindings.FirstOrDefault(b => b.Protocol.Equals(bindingProtocol,StringComparison.OrdinalIgnoreCase)&& b.BindingInformation.Equals(bindingInformation,StringComparison。 OrdinalIgnoreCase)); - granadaCoder
if(null == foundBinding){////添加绑定session.Log(“关于添加到Site.Bindings.SITE ='{0}',BINDINGINFORMATION ='{1}',BINDINGPROTOCOL ='{2}'。 “,sitename,bindingInformation,bindingProtocol); site.Bindings.Add(bindingInformation,bindingProtocol); - granadaCoder
serverManager.CommitChanges(); session.Log(“ServerManager.CommitChanges成功添加到Site.Bindings.SITE ='{0}',BINDINGINFORMATION ='{1}',BINDINGPROTOCOL ='{2}'。”,sitename,bindingInformation,bindingProtocol); result = true; } - granadaCoder
else {session.Log(string.Format(“Binding already exists。(SiteName ='{0}',bindingInformation ='{1}',bindingProtocol ='{2}')”,sitename,bindingInformation,bindingProtocol)); result = true; / *如果绑定已经存在,则不会失败,重点是具有绑定* /} - granadaCoder


这是在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>

如果世界上一切都很好,现在将更新协议。


5
2017-12-05 09:49



好的,谢谢! - Ivan
打的好。我正在通过命名管道部署IIS中托管的WCF服务。通过一些调整,我现在在我启用的协议中有“http,net.pipe”。这不在默认的wix-installer中是一个失望。 - granadaCoder


你可以看看 本文 在MSDN上。最后有一节说明如何使用 托管API 实现配置启用WAS的服务。我不熟悉Wix,但您可以使用并将此代码插入一些自定义部署步骤。


1
2017-11-22 12:27





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

你也可以找到 这个帖子 有趣的是 - 它提示如何在MSBuild脚本中实现类似的功能,但您应该能够轻松地将其转换为自定义操作。

祝你好运!


1
2017-11-25 12:12