首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Wix3.5项目/设置将net.tcp添加到“已启用的协议”中?

如何使用Wix3.5项目/设置将net.tcp添加到“已启用的协议”中?
EN

Stack Overflow用户
提问于 2010-06-29 20:40:51
回答 4查看 3.3K关注 0票数 11

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

我想让我们的部署工作变得更简单,并自动化添加net.tcp的过程。我已经了解了WixIisExtension.dll并使用了它的一些有用的功能(创建网站,虚拟。目录等)。

是否可以使用WixIisExtension启用net.tcp协议?如果没有,我如何才能做到这一点?

EN

回答 4

Stack Overflow用户

发布于 2012-06-21 22:52:54

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

在此项目中,添加对程序集Microsoft.Web.Administration的引用,它可以在以下位置找到: C:\Windows\System32\inetsrv,这是添加协议所必需的。

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

代码语言:javascript
复制
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元素中的某个位置添加属性:

代码语言:javascript
复制
<!-- Properties -->
<Property Id="SITE" Value="MySite" />
<Property Id="VIRTUALDIRECTORYALIAS" Value="MyVirtDirectoryAlias" />
<Property Id="PROTOCOLS" Value="http,net.tcp" />

在下面添加二进制元素:

代码语言:javascript
复制
<!-- Binaries -->
<Binary Id="CustomAction.EnableProtocols" SourceFile="$(var.Setup.CustomAction.EnableProtocols.TargetDir)Setup.CustomAction.EnableProtocols.CA.dll" />

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

在下面添加自定义操作:

代码语言:javascript
复制
<!-- Custom Actions -->
<CustomAction Id="EnableProtocols" BinaryKey="CustomAction.EnableProtocols" DllEntry="EnableProtocols" Execute="immediate" Return="check" />

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

代码语言:javascript
复制
<!-- Installation Sequence -->
<InstallExecuteSequence>
  <Custom Action="EnableProtocols" After="InstallFinalize">NOT Installed</Custom>
</InstallExecuteSequence>

就这样。应该行得通。感谢Darin Dimitrov提供上述链接。

票数 7
EN

Stack Overflow用户

发布于 2013-12-05 17:49:16

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

获取对appcmd.exe的引用:

代码语言:javascript
复制
<Property Id="APPCMD">
  <DirectorySearch Id="FindAppCmd" Depth="1" Path="[WindowsFolder]\system32\inetsrv\">
    <FileSearch Name="appcmd.exe"/>
  </DirectorySearch>
</Property>

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

代码语言:javascript
复制
<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中添加

代码语言:javascript
复制
<InstallExecuteSequence>
  ...
  <Custom Action="SetEnableNetTCPCommmand" After="InstallExecute">APPCMD AND NOT Installed</Custom>
  <Custom Action="EnableNetTCP" After="SetEnableNetTCPCommmand">APPCMD AND NOT Installed</Custom>
  ...
</InstallExecuteSequence>

如果世界上一切顺利,那么现在就会更新协议。

票数 5
EN

Stack Overflow用户

发布于 2010-11-22 20:27:38

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3140662

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档