Search code examples
c#installationdeploymentwixwixsharp

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


Im trying to add all output files of a given path to the installation that end in either .exe, .dll or .config, but the ways I have tried so far haven't worked.

This is what I've tried:

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***);
        }

as well as simply doing

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***);
            }

Using the first method, I only get all the files from the folders but not the nested folders nor their contents. Using the second method, I get nothing at all.

How can I fix those, or what is an entirely different way I can get this to work?

Thanks!


Solution

  • You can just use Files.FromBuildDir(@"your\build\dir\", ".exe|.dll|.config"). This should collect all files recursively and preserve directory structure. You can also check corresponding sample or Files class sources - there are some constructors exists, which may be also helpful.