0

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!

Felix t
  • 19
  • 6
  • My suggestion try to use the recursion method to get all file from folder & nested folder. – Prabhat Jul 07 '21 at 14:41
  • isnt that exactly what i tried? the nested folders dont get installed for some reason the way i did it – Felix t Jul 07 '21 at 16:04
  • Sorry, As per your questions I thought you need that..Then Please read your questions proper and edit it.. So other can easily understand. – Prabhat Jul 08 '21 at 00:42
  • Are you get all contents in getContens() method? I think you missed contents/file of nested folder. – Prabhat Jul 08 '21 at 00:50
  • i recursively call getContents() to add the contents of the nested folders. but during the installation the folders arent created in the first place – Felix t Jul 08 '21 at 08:45

1 Answers1

0

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.

Serg
  • 3,454
  • 2
  • 13
  • 17
  • cool this works! weird thing is the documentation of Files.FromBuildDir says that its just a simplified version of what I did with the constructor for Files. maybe i messed something in the filter up? thanks anyway! – Felix t Jul 14 '21 at 06:28
  • In your snippet with `Files` constructor you missed the `\*.*` match pattern and this significantly changed constructor behaviour (and this is by design) – Serg Jul 14 '21 at 07:49