Wix安装程序中的文件浏览对话框

4
我正在使用 Wix Installer v3.9 创建一个安装程序。我想在安装完成后弹出一个文件浏览对话框。用户可以从目录中选择多个文件。然后,这些文件路径必须作为命令行参数传递给一个exe文件。
我该如何做呢?Wix BrowseDlg 只能选择目录。
非常感谢您的帮助。
1个回答

10
据我所知,wix工具集没有文件浏览控件。因此,我通常使用C#自定义操作来完成此任务。
尝试使用此示例,并根据您的需求进行自定义。
using WinForms = System.Windows.Forms;
using System.IO;
using Microsoft.Deployment.WindowsInstaller;

[CustomAction]
public static ActionResult OpenFileChooser(Session session)
{
    try
    {
        session.Log("Begin OpenFileChooser Custom Action");
        var task = new Thread(() => GetFile(session));
        task.SetApartmentState(ApartmentState.STA);
        task.Start();
        task.Join();
        session.Log("End OpenFileChooser Custom Action");
    }
    catch (Exception ex)
    {
        session.Log("Exception occurred as Message: {0}\r\n StackTrace: {1}", ex.Message, ex.StackTrace);
        return ActionResult.Failure;
    }
    return ActionResult.Success;
}

private static void GetFile(Session session)
{
    var fileDialog = new WinForms.OpenFileDialog { Filter = "Text File (*.txt)|*.txt" };
    if (fileDialog.ShowDialog() == WinForms.DialogResult.OK)
    {
        session["FILEPATH"] = fileDialog.FileName;
    }
}

太好了!我该如何将所选路径显示在CustomDialog的文本框中?我是从BrowseFile调用它的。 - D. Bermudez
2
文本框的值应该是[PropertyName]。这样可以确保属性和文本框中的值同步。 - Ashish Kamat

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接