【问题标题】:How to add all contents of build folder to installation using Wix#?如何使用 Wix# 将构建文件夹的所有内容添加到安装中?
【发布时间】:2021-09-18 01:11:15
【问题描述】:

我正在尝试将给定路径的所有输出文件添加到以 .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***);
            }

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

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

谢谢!

【问题讨论】:

  • 我的建议尝试使用递归方法从文件夹和嵌套文件夹中获取所有文件。
  • 这不正是我尝试过的吗?由于某种原因,嵌套文件夹没有按照我的方式安装
  • 对不起,根据您的问题,我认为您需要那个..然后请正确阅读您的问题并进行编辑..以便其他人可以轻松理解。
  • 您是否在 getContens() 方法中获取所有内容?我认为您错过了嵌套文件夹的内容/文件。
  • 我递归调用 getContents() 来添加嵌套文件夹的内容。但是在安装过程中,文件夹不是首先创建的

标签: c# installation deployment wix wixsharp


【解决方案1】:

您可以使用Files.FromBuildDir(@"your\build\dir\", ".exe|.dll|.config")。这应该递归收集所有文件并保留目录结构。您也可以查看对应的sampleFilessources - 存在一些构造函数,这可能也有帮助。

【讨论】:

  • 酷这个作品!奇怪的是 Files.FromBuildDir 的文档说它只是我对 Files 的构造函数所做的简化版本。也许我把过滤器里的东西弄乱了?还是谢谢!
  • 在带有 Files 构造函数的 sn-p 中,您错过了 \*.* 匹配模式,这显着改变了构造函数的行为(这是设计使然)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-06-22
  • 1970-01-01
  • 1970-01-01
  • 2018-02-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多