Problem:
WiX uses an XML file for instructions on what directories to add to the msi package. I had no problem in recursively going through the source directory and pulling all sub-directories and files, the trouble I have is inserting those entries into an XML file with the same depth as in the file system.
Working Solution:
After over a week of doing build, run and repeat, I figured I should use the stack in C#, eureka! Before I was bouncing around some methods until I got all files and directories out, the good things was that they came out in order, the bad thing was that it got complicated because I was passing too many parameters, an XMLELEMENT, XMLDOCUMENT, the directory to read, and then I couldn’t attach a sub-directory to a directory, because it thinks the directory hasn’t been created yet. Ahh, what a mess.
I implemented the stack in a while loop, pushed directories on it, and at the same time read the directory on the top of the stack for files. It’s a little complicated when looking at how the directories are read, but I realized it was backwards, because it has the last directory added on the top of the stack.
XmlElement xeDir; dirStack.Push(args[0]); int dirCount = -1; int uniqueFile = 0; while (dirStack.Count > 0) { String curDir = dirStack.Pop(); if (dirCount == dirStack.Count) foreach (String fileName in Directory.GetFiles(curDir, “*.*”)) XmlElement xeCom = xmlDoc.CreateElement(“Component”); XmlElement xeFile = xmlDoc.CreateElement(“File”); foreach (String fileName in Directory.GetFiles(curDir, “*.*”)) |
Current Problem:
I am able to attach sub-directories to the parent directory in the XML file, but if there is another sub-directory below the first sub-directory, I can’t attach it that deep.
How do you ensure that the Component/@Guid’s don’t break the Component Rules?
The .NET Framework provides a Guid structure, which can create a unique guid, then just send it to toString().toUpper() to make it an upper case string so I can add it as an attribute of Component.
Here’s the call:
Guid.NewGuid().ToString().ToUpper()
I just did it in the setAttribute method of the XmlElement:
xeCom.SetAttribute(”Guid”, Guid.NewGuid().ToString().ToUpper());
The Guid’s are supposed to be completely unique, do you know any other rules for Component?