Is it possible to dynamically add directories to a project?

Jul 16, 2015 at 9:47 PM
I'm trying to add a directory to and existing Project object, but I'm having some trouble getting it to work. I've attempted to do it like this:
                .Add(new Dir() { Name = "SomeDir" });
Obviously, this doesn't work, but I can't figure out why not. Is it possible to do something like this, and if so, how?
Jul 17, 2015 at 3:17 AM
Edited Jul 17, 2015 at 6:19 AM
It fails because Dirs is an array and you cannot change it. It is the same case as with the call myString.Replace(" ", "_") not changing the myString value.

You need to use Dir.AddDir extension method:
using WixSharp;
using WixSharp.CommonTasks;
var dir = project.ResolveWildCards(ignoreEmptyDirectories: true)
dir.AddDir(new Dir() { Name = "SomeDir" });


project.ResolveWildCards(ignoreEmptyDirectories: true)
       .AddDir(new Dir() { Name = "SomeDir" });
Jul 17, 2015 at 9:06 AM

It is also possible to extend the project.Dirs array:

Array.Resize(ref project.Dirs, project.Dirs.Length + x);
where x is a desired number....

and then you can just do something like:
project.Dirs[x] = newDir;

This should work. :)
Jul 17, 2015 at 1:12 PM
Ah, ok. That makes sense. Thank you!