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

Dot*_*ter 11 wix wcf-binding net.tcp iis-7.5 wix3.5

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

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

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

ms0*_*007 7

将新项目添加到安装解决方案(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;
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

请注意,我假设这里有三处房产: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" />
Run Code Online (Sandbox Code Playgroud)

下面添加二进制元素:

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

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

下面添加自定义操作:

<!-- Custom Actions -->
<CustomAction Id="EnableProtocols" BinaryKey="CustomAction.EnableProtocols" DllEntry="EnableProtocols" Execute="immediate" Return="check" />
Run Code Online (Sandbox Code Playgroud)

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

<!-- Installation Sequence -->
<InstallExecuteSequence>
  <Custom Action="EnableProtocols" After="InstallFinalize">NOT Installed</Custom>
</InstallExecuteSequence>
Run Code Online (Sandbox Code Playgroud)

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


bri*_*ler 5

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

获取对appcmd.exe的引用:

<Property Id="APPCMD">
  <DirectorySearch Id="FindAppCmd" Depth="1" Path="[WindowsFolder]\system32\inetsrv\">
    <FileSearch Name="appcmd.exe"/>
  </DirectorySearch>
</Property>
Run Code Online (Sandbox Code Playgroud)

定义以下自定义操作(属性[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" />
Run Code Online (Sandbox Code Playgroud)

现在在InstallExecuteSequence添加

<InstallExecuteSequence>
  ...
  <Custom Action="SetEnableNetTCPCommmand" After="InstallExecute">APPCMD AND NOT Installed</Custom>
  <Custom Action="EnableNetTCP" After="SetEnableNetTCPCommmand">APPCMD AND NOT Installed</Custom>
  ...
</InstallExecuteSequence>
Run Code Online (Sandbox Code Playgroud)

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


Dar*_*rov 1

你可以看看MSDN上的这篇文章。最后有一节介绍了如何使用托管 API来配置启用 WAS 的服务。我不熟悉 Wix,但您可能可以使用此代码并将其插入到某些自定义部署步骤中。