如何使用 Wix# 将构建文件夹的所有内容添加到安装中?

How to add all contents of build folder to installation using Wix#?

我正在尝试将给定路径的所有以 .exe、.dll 或 .config 结尾的输出文件添加到安装中,但到目前为止我尝试过的方法都没有奏效。

这是我试过的:

private static WixEntity[] getContents(string directory)
    {
        WixEntity[] contents = System.IO.Directory.GetFiles(directory)
                        .Where(f => f.EndsWith(".dll")
                                    || f.EndsWith(".exe")
                                    || f.EndsWith(".config"))
                        .Select(f => new File(f))
                        .ToArray();
        contents = contents.Concat(System.IO.Directory.GetDirectories(directory, string.Empty, System.IO.SearchOption.TopDirectoryOnly)
                        .Select(d => new Dir(d.Split('\').Last(), getContents(d)))
                        .ToArray()).ToArray();
        return contents;
    }

private static string buildMsi()
        {
            var project =
                new ManagedProject(productName,
                    new Dir($"%ProgramFiles%\{companyName}",
                        new Dir($"{productName} Files", getContents(clientFolderPath)),
        ***some other irrellevant stuff***);
        }

以及简单地做

private static string buildMsi()
            {
                var project =
                    new ManagedProject(productName,
                        new Dir($"%ProgramFiles%\{companyName}",
                            new Dir($"{productName} Files", new Files(clientFolderPath, f => f.EndsWith(".dll")
                                || f.EndsWith(".exe")
                                || f.EndsWith(".config")),
            ***some other irrellevant stuff***);
            }

使用第一种方法,我只能从文件夹中获取所有文件,而不是嵌套文件夹及其内容。 使用第二种方法,我什么也得不到。

我该如何解决这些问题,或者有什么完全不同的方法可以让它发挥作用?

谢谢!

您可以直接使用 Files.FromBuildDir(@"your\build\dir\", ".exe|.dll|.config")。这应该递归地收集所有文件并保留目录结构。您还可以检查相应的 sample or Files class sources - 存在一些构造函数,这可能也会有所帮助。