我们有一些安装WCF服务的MSI包(由WIX生成)。这些服务中的大多数都需要net.tcp来进行端点绑定。
我想让我们的部署更轻松,并自动完成添加net.tcp的过程。 我已经知道WixIisExtension.dll并使用它的有用功能(创建网站,virt。目录等)。
我可以使用WixIisExtension来启用net.tcp协议吗? 如果没有,我怎么能实现呢?
我们有一些安装WCF服务的MSI包(由WIX生成)。这些服务中的大多数都需要net.tcp来进行端点绑定。
我想让我们的部署更轻松,并自动完成添加net.tcp的过程。 我已经知道WixIisExtension.dll并使用它的有用功能(创建网站,virt。目录等)。
我可以使用WixIisExtension来启用net.tcp协议吗? 如果没有,我怎么能实现呢?
将新项目添加到安装解决方案(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提供上述链接。
这是在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=""[APPCMD]" set app "[WEB_SITE_NAME]/[WEB_APP_NAME]" /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>
如果世界上一切都很好,现在将更新协议。
使用标准无法做到这一点 WiXIIsExtension, 我所知道的。因此,您唯一的选择是自定义操作。
你也可以找到 这个帖子 有趣的是 - 它提示如何在MSBuild脚本中实现类似的功能,但您应该能够轻松地将其转换为自定义操作。
祝你好运!