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!

5
  • My suggestion try to use the recursion method to get all file from folder & nested folder. Commented Jul 7, 2021 at 14:41
  • isnt that exactly what i tried? the nested folders dont get installed for some reason the way i did it Commented Jul 7, 2021 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. Commented Jul 8, 2021 at 0:42
  • Are you get all contents in getContens() method? I think you missed contents/file of nested folder. Commented Jul 8, 2021 at 0: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 Commented Jul 8, 2021 at 8:45

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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!
In your snippet with Files constructor you missed the \*.* match pattern and this significantly changed constructor behaviour (and this is by design)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.