0

在使用http://wixtoolset.org/为我的应用程序创建安装程序工作了很长时间之后,我使用的是 3.10v,最后我得到了工作的 .msi 安装程序文件。

但我希望 IIS 服务器中存在的网站列表在安装期间显示在下拉列表中,以便我可以从 IIS 服务器中选择现有网站并使用它来安装我的应用程序。

我在我的 UI 页面(.wxs 文件)中创建了一个 ComboBox 控件,并坚持编写自定义操作,任何帮助非常感谢!

4

1 回答 1

1

只需添加这样的自定义操作:

  <CustomAction Id="GetIISWebsitesID" BinaryKey="GetIISWebsites" DllEntry="CustomAction1" Execute="immediate" Return="check"></CustomAction>
  <Binary Id="GetIISWebsites" SourceFile="..\GetIISWebsites\bin\Debug\GetIISWebsites.CA.dll"/>

在您的 wxs 文件中,自定义操作的代码如下:

命名空间 GetIISWebsites
{
    公共类 CustomActions
    {
        [自定义动作]
        公共静态 ActionResult CustomAction1(Session xiSession)
        {
            System.Diagnostics.Debugger.Launch();
            Microsoft.Deployment.WindowsInstaller.View lView = xiSession.Database.OpenView("DELETE FROM ComboBox WHERE ComboBox.Property='xxxxxxxx'");
            lView.Execute();

            lView = xiSession.Database.OpenView("SELECT * FROM ComboBox");
            lView.Execute();
            列出实例 = RetrieveIISWebsites();
            整数计数器 = 0;
            整数索引 = 0;
            布尔标志 = 假;
            尝试
            {
                foreach(实例中的字符串 str)
                {
                    记录 lRecord = xiSession.Database.CreateRecord(4);
                    lRecord.SetString(1, "xxxxxxxx");
                    lRecord.SetInteger(2, Index);
                    lRecord.SetString(3, str);
                    lRecord.SetString(4, str);
                    lView.Modify(ViewModifyMode.InsertTemporary, lRecord);
                    计数器=索引;
                    ++索引;
                }
            }
            捕捉(例外前)
            {
                ex.ToString();
                xiSession.Log("异常详情:" + ex.Message);
            }
            lView.Close();

            xiSession.Log("关闭视图");
            lView.Close();
            返回 ActionResult.Success;
        }
        私有静态列表 RetrieveIISWebsites()
        {
            列表结果 = 新列表();
            var 网站 = GetSites();
            foreach(网站中的网站)
            {
                结果.添加(站点。名称);
            }

            返回结果;
        }
        私有静态 SiteCollection GetSites()
        {
            var iisManager = new ServerManager();
            SiteCollection 站点 = iisManager.Sites;
            返回站点;
        }
    }
}

这里 xxxxxxxx 是绑定到组合框的属性。

从 C:\Program Files (x86)\WiX Toolset v3.9\bin 文件夹中添加 Microsoft.Web.Administration.dll。

如果回答正确或有任何疑问,请告诉我。

于 2016-01-20T12:41:36.423 回答