I have several related Windows registry entries that I want packaged inside an MSI, so that 1) there is an uninstall process, and 2) The fact that these registry entries hav
Using the Wix XML code Ryan J provided, plus the example "InjectXML" from the Wix# samples code, I was successful in generating the wxs file and getting a working MSI, all while still staying within the Wix# coding environment in Visual Studio.
Here is the relevant .wxs XML that was being generated before, under the element:
So what needs to happen is: 1) Remove the "" element, which is under Product/Directory/Directory/Component. Ryan J's example clearly showed that it goes under the "Component" that is associated with the first "Directory" to be created, which is in turn under the "TARGETDIR", in the XML that Wix# generates.
2) Insert the element syntax, "", under the element Product/Directory/Directory/Component. While I believe it may also work to reference the Id "INSTALLDIR.EmptyDirectory"in this element, I used the Id "TARGETDIR" and it worked the way I wanted.
Here is the resulting Wix# code that injects the XML as supplied by Ryan J.
internal class Script
{
public static void Main()
{
// Define a new Installer Project object
var project = new Project("SetupMyApplicationEventLog" ,
// Provide dummy "Temp" install directory to satisfy WiX# Syntactical requirement. There are no actual files being installed.
new Dir(@"TempDeleteMe"),
...
// Hook up a delegate to the "WixSourceGenerated" event, fires when .wxs file is fully created
Compiler.WixSourceGenerated += InjectXMLElement;
// Trigger the MSI file build
Compiler.BuildMsi(project);
...
/// Insert XML elements and attributes into the generated .wxs file
static void InjectXMLElement(System.Xml.Linq.XDocument document)
{
// Remove the tag from Directory element -- we don't want to create it
var createFolderElement = document.Root.Select("Product/Directory/Directory/Component/CreateFolder");
createFolderElement.Remove();
// To cause the folder to not be created on the target system, add this element:
//
var componentElement = document.Root.Select("Product/Directory/Directory/Component");
componentElement.Add(new XElement("RemoveFolder",
new XAttribute("Id", "RemoveTarget"),
new XAttribute("Directory", "TARGETDIR"),
new XAttribute("On","both")));
}