在wix安装的下拉列表中绑定IIS本地网站?

Bind IIS local websites in dropdown list of wix installation?

在使用 http://wixtoolset.org/ 为我的应用程序创建安装程序并使用 3.10v 后,我终于得到了工作的 .msi 安装程序文件。

但我希望 IIS 服务器中存在的网站列表在安装过程中显示在下拉列表中,这样我就可以 select IIS 服务器中的现有网站并使用它来安装我的申请。

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

只需像这样添加一个自定义操作:

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

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

namespace GetIISWebsites
{
    public class CustomActions
    {
        [CustomAction]
        public static 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();
            List instances = RetrieveIISWebsites();
            int Counter = 0;
            int Index = 0;
            bool flag = false;
            try
            {
                foreach (string str in instances)
                {
                    Record 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);
                    Counter = Index;
                    ++Index;
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
                xiSession.Log("Exception Details: " + ex.Message);
            }
            lView.Close();

            xiSession.Log("Closing view");
            lView.Close();
            return ActionResult.Success;
        }
        private static List RetrieveIISWebsites()
        {
            List result = new List();
            var websites = GetSites();
            foreach (Site site in websites)
            {
                result.Add(site.Name);
            }

            return result;
        }
        private static SiteCollection GetSites()
        {
            var iisManager = new ServerManager();
            SiteCollection sites = iisManager.Sites;
            return sites;
        }
    }
}

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

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

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