How to adjust attributes of "Component" block

Jan 21, 2016 at 12:12 PM
I have a "File" entity that I would like to mark as "Permanent = "Yes"" in the resulting WXS file. Unfortunately in WXS this need to be in the surrounding "Component" tag not on the "File" tag itself. Here is an example:

I have
       <Component ....>
          <File ... />
        </Component>
I need it to have
       <Component Permanent="Yes" ...">
          <File ... />
        </Component>
Any way I can do this besides manually changing the WXS file after creation?

BTW. Thanks for Wix#, it has saved a ton of effort in creating MSI files! Really appreciated!!!
Jan 21, 2016 at 2:00 PM
Found it. Need to use injection....
    Compiler.WixSourceGenerated += document =>
    {
        var components = document.FindAll("Component");
        foreach(var component in components)
        {
            if(component.Attribute("Id").Value.ToString().ToUpper().Trim().EndsWith(".PPLC"))
            {
                component.SetAttributeValue("Permanent", "yes");
            }
        }
    };
Thanks
Coordinator
Jan 21, 2016 at 11:03 PM
Or better yet set it directly from the contained entity definition with "Component:" selector:
new RegValue(RegistryHive.LocalMachine, 
           @"Software\My Company\My Product", 
            "InstallationDirectory", 
            "[INSTALLDIR]") 
           { AttributesDefinition = "Component:Permanent=yes" });

new File(@"Files\Bin\MyApp.exe")
{ 
    AttributesDefinition = "Component:Permanent=yes" 
};
Coordinator
Jan 21, 2016 at 11:13 PM
Also be aware that there are a few convenient attribute matching method extensions for XElement:
if (e.HasAttribute("Id", "MyAppID"))
    ...
if (e.HasAttribute("Id", id => id.EndsWith(".PPLC")))
    ...