RegFile -- add a constructor that assigns it to a Wix# "Feature"

Feb 4, 2015 at 7:45 PM
I can do this to import a registry file and it works great, as long as I'm not dealing with multiple "Features" where I want each feature to have its own registry entry .reg file:
   new RegFile(Path.Combine(myRegFileSourceFolder, "PGP2.PGPWrapper.reg")
However, if I want to have each feature have its own associated registry entries, I'd need to do something like this:
...
        Feature PGPLogFeature = new Feature("PGP Event Log Entries");
        Feature RunAndWaitLogFeature = new Feature("RunAndWait Event Log Entries");

        new RegFile(PGPLogFeature, Path.Combine(myRegFileSourceFolder, "PGP2.PGPWrapper.reg"),

        new RegFile(RunAndWaitLogFeature, Path.Combine(myRegFileSourceFolder, "Logevent2.LogEvent.reg")
...

I've tried including the RegFile statements below separate "Dir" entries that ARE assigned to a feature. However, this does not work; at Wix# run/WiX build time, the WiX compiler reports an ERROR that the registry entries "are not assigned to any feature".

Is it possible in Wix# to have a RegFile constructor that accepts a Feature ID, so that the resulting registry entries are then assigned to the feature in the RegFile constructor?
Feb 17, 2015 at 12:50 PM
Edited Mar 12, 2015 at 8:44 AM
Yes it makes sense. I have added it as a feature request.
Will be done in the next release.
Mar 2, 2015 at 10:39 PM
It works!! Loaded up Release v1.0.8.0, set up my features of Dev, QA, and Prod, and assigned each entry to a feature.

Excerpt from my working installer below. There are two .reg files per feature. The features are:
"Dev ODBC Datasource"
"QA ODBC Datasource"
"Prod ODBC Datasource"

Each ODBC datasource points at a different database server and database.

The installer uses the FeatureTree UI to allow the user to select which feature(s) to install.
project.UI = WUI.WixUI_FeatureTree;
Each feature, if selected, will cause the two .reg files, File01 and File02, for that feature, to be installed on the target system.
Code is below. Each set of 2 .reg files is located in a subfolder of the project named to match, e.g., Dev, QA, Prod. Each file is also named so it includes the environment name, Dev/QA/Prod, as the starting part of the filename. Thus the Path.Combine statements, to pull in the right registry file for the environment, Dev in this case, for the DevDataSource feature:
                new RegFile(DevDataSource, Path.Combine(myRegFileSourceFolder, DevTargetEnvironment, DevTargetEnvironment + " " + myRegistryInputFile01)),
                new RegFile(DevDataSource, Path.Combine(myRegFileSourceFolder, DevTargetEnvironment, DevTargetEnvironment + " " + myRegistryInputFile02)),
   internal class Script
    {
        public static void Main()
        {
            // Environments to build installer for
            const string DevTargetEnvironment = "Dev";
            const string QATargetEnvironment = "QA";
            const string ProdTargetEnvironment = "Prod";

            // Name of installer to be generated
            const string myInstallerName = @"SetupLettersODBC";
            const string MSISuffix = ".msi";
            const string WiXSuffix = ".wxs";

            // Where the .reg source files are pulled from to build the MSI
            const string myRegFileSourceFolder = @"C:\MyAppFolder\Setup and Deployment\SetupLettersODBC\ResourceFiles\" ;

            // Where the MSI and .wxs files get created by WiX build process
            const string myBuildFolder = @"C:\MyAppFolder\Setup and Deployment\SetupLettersODBC\Bin\debug\";

            // Where the completed MSI and .wxs files get placed for pickup
            const string myOutputFolder = @"C:\MyAppFolder\Setup and Deployment\SetupLettersODBC\Output\" ;

            string myRegistryInputFile01 = "Letters ODBC DS 01 HKLM ODBC-ODBCINI-ODBC Data Sources.reg";
            const string myRegistryInputFile02 = "Letters ODBC DS 02 HKLM Software-ODBC-ODBCINI-EnvDrivSQL.reg";

            Feature DevDataSource = new Feature("Dev ODBC Datasource");
            Feature QADataSource = new Feature("QA ODBC Datasource");
            Feature ProdDataSource = new Feature("Prod ODBC Datasource");

            // Define a new Installer Project object
            var project = new Project(
                myInstallerName,
                new RegFile(DevDataSource, Path.Combine(myRegFileSourceFolder, DevTargetEnvironment, DevTargetEnvironment + " " + myRegistryInputFile01)),
                new RegFile(DevDataSource, Path.Combine(myRegFileSourceFolder, DevTargetEnvironment, DevTargetEnvironment + " " + myRegistryInputFile02)),

                new RegFile(QADataSource, Path.Combine(myRegFileSourceFolder, QATargetEnvironment, QATargetEnvironment + " " + myRegistryInputFile01)),
                new RegFile(QADataSource, Path.Combine(myRegFileSourceFolder, QATargetEnvironment, QATargetEnvironment + " " + myRegistryInputFile02)),

                new RegFile(ProdDataSource, Path.Combine(myRegFileSourceFolder, ProdTargetEnvironment, ProdTargetEnvironment + " " + myRegistryInputFile01)),
                new RegFile(ProdDataSource, Path.Combine(myRegFileSourceFolder, ProdTargetEnvironment, ProdTargetEnvironment + " " + myRegistryInputFile02))

                );

            // Set the properties of the setup project
            // Set UI to feature selection
            project.UI = WUI.WixUI_FeatureTree;
            project.Manufacturer = "MyCompany";
            project.OutFileName = myInstallerName;
            project.GUID = new Guid("E5AB5105-4D42-40BE-B89F-02BA20F99999");
            // Assign version # to setup MSI property of type System.Version 
            project.Version = new Version(1, 0, 0, 0);

            // Add the x86 attribute to the package, to force a 32-bit MSI to be created
            project.Package.AttributesDefinition = "Platform=x86";

            // Trigger the MSI file build
            Compiler.BuildMsi(project);
            //// Also create the .wxs file so we can see what was sent to WiX to build the MSI
            Compiler.BuildWxs(project);

            Console.WriteLine("productVersion=" + project.Version);
            // Copy .MSI and .WXS files to Output folder
            string builtMSIFile = Path.Combine(myBuildFolder, myInstallerName + MSISuffix);
            string builtWiXFile = Path.Combine(myBuildFolder, myInstallerName + WiXSuffix);
            string outputMSIFile = Path.Combine(myOutputFolder, myInstallerName + MSISuffix);
            string outputWiXFile = Path.Combine(myOutputFolder, myInstallerName + WiXSuffix);
            bool exists = System.IO.Directory.Exists(myOutputFolder);
            if(!exists) System.IO.Directory.CreateDirectory(myOutputFolder);
            WindowsHelpers.MakeFileWriteable(outputMSIFile);
            WindowsHelpers.MakeFileWriteable(outputWiXFile);
            File.Copy(builtMSIFile, outputMSIFile, true);
            File.Copy(builtWiXFile, outputWiXFile, true);
            Console.WriteLine("Output file copied to " + outputMSIFile);
            Console.ReadLine();
        }
  }