WixSharp.Project.ResolveWildCards C# (CSharp) Method

ResolveWildCards() public method

Resolves all wild card specifications if any.

This method is called by Compiler during the compilation. However it might be convenient to call it before the compilation if any files matching the wild card mask need to be handled in special way (e.g. shortcuts created). See WildCard Files example.

ResolveWildCards should be called only after T:WixSharp.WixProject.SourceBaseDir is set. Otherwise wild card paths may not be resolved correctly.
public ResolveWildCards ( bool ignoreEmptyDirectories = false ) : Project
ignoreEmptyDirectories bool if set to true empty directories are ignored and not added to the project.
return Project
        public Project ResolveWildCards(bool ignoreEmptyDirectories = false)
        {
            int iterator = 0;
            var dirList = new List<Dir>();
            var fileList = new List<File>();

            dirList.AddRange(Dirs);

            while (iterator < dirList.Count)
            {
                foreach (Files dirItems in dirList[iterator].FileCollections)
                    foreach (WixEntity item in dirItems.GetAllItems(SourceBaseDir))
                        if (item is DirFiles)
                            dirList[iterator].DirFileCollections = dirList[iterator].DirFileCollections.Add(item as DirFiles);
                        else if (item is Dir)
                            dirList[iterator].Dirs = dirList[iterator].Dirs.Add(item as Dir);

                foreach (Dir dir in dirList[iterator].Dirs)
                    dirList.Add(dir);

                foreach (DirFiles coll in dirList[iterator].DirFileCollections)
                    dirList[iterator].Files = dirList[iterator].Files.Combine<File>(coll.GetFiles(SourceBaseDir));

                //clear resolved collections
                dirList[iterator].FileCollections = new Files[0];
                dirList[iterator].DirFileCollections = new DirFiles[0];

                iterator++;
            }

            if (ignoreEmptyDirectories)
            {
                var emptyDirs = AllDirs.Where(d => !d.Files.Any() && !d.Dirs.Any());

                emptyDirs.ForEach(emptyDir => AllDirs.ForEach(d =>
                                              {
                                                  if (d.Dirs.Contains(emptyDir))
                                                      d.Dirs = d.Dirs.Where(x => x != emptyDir).ToArray();
                                              }));
            }

            return this;
        }

Usage Example

Example #1
0
    public static void Main(string[] args)
    {
        var project =
            new Project("MyProduct",
                new Dir(@"%ProgramFiles%\My Company\My Product",

                    //new Dir("Documentation", new Files(@"\\BUILDSERVER\My Product\Release\Documentation\*.*")), //uncomment if you have a real remote files to install

                    new Files(@"..\Release Folder\Release\*.*",
                              f => !f.EndsWith(".obj") &&
                                   !f.EndsWith(".pdb")),

                    new ExeFileShortcut("Uninstall My Product", "[System64Folder]msiexec.exe", "/x [ProductCode]")));

        project.SourceBaseDir = @"E:\Galos\Projects\WixSharp\src\WixSharp.Samples\Wix# Samples\Release Folder";

        project.GUID = new Guid("6f330b47-2577-43ad-9095-1561ba25889b");

        project.ResolveWildCards(ignoreEmptyDirectories: true)
               .FindFile((f) => f.Name.EndsWith("MyApp.exe"))
               .First()
               .Shortcuts = new[] {
                                       new FileShortcut("MyApp.exe", "INSTALLDIR"),
                                       new FileShortcut("MyApp.exe", "%Desktop%")
                                  };

        Compiler.PreserveTempFiles = true;
        Compiler.EmitRelativePaths = false;
        Compiler.BuildMsi(project);
    }
All Usage Examples Of WixSharp.Project::ResolveWildCards