Quantcast
Channel: wixsharp Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1354

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

$
0
0
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();
        }
  }

Viewing all articles
Browse latest Browse all 1354

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>