Bootstrapper Installer Sample with Embedded C++ 2013 and 2015 Redist

May 18, 2016 at 1:13 AM
Edited May 18, 2016 at 4:04 PM
Here's a Bootstrapper that installs C++ redist libraries embedded in the installer:
using System;
using System.Xml.Linq;
using WixSharp;
using WixSharp.Bootstrapper;

namespace SetupBootstrapper {
    class Program {
        static void Main() {

            string productMsi = BuildMsi();

            var bootstrapper =
              new Bundle("MyProduct"
                    , new PackageGroupRef("NetFx40Web")
                    , new ExePackage {
                        Name = "C++ 2013 Runtime Libraries",
                        SourceFile = @"redist\vc2013redist_x64.exe",
                        Compressed = true,
                        PerMachine = true,
                        Permanent = true,
                        Vital = true,
                        DetectCondition = "MYCPP2013",
                        InstallCommand = "/passive /norestart", // "/q"
                    }
                    , new ExePackage {
                        Name = "C++ 2015 Runtime Libraries",
                        SourceFile = @"redist\vc2015redist_x64.exe",
                        Compressed = true,
                        PerMachine = true,
                        Permanent = true,
                        Vital = true,
                        DetectCondition = "MYCPP2015",
                        InstallCommand = "/passive /norestart", // "/q"
                    }
                    , new MsiPackage(productMsi) { DisplayInternalUI = true });

            bootstrapper.AddWixFragment("Wix/Bundle"
                // These search keys for C++ 2013 and 2015 redist are from:
                // http://stackoverflow.com/questions/12206314/detect-if-visual-c-redistributable-for-visual-studio-2012-is-installed
                , new UtilRegistrySearch {
                    Root = Microsoft.Win32.RegistryHive.LocalMachine,
                    Key = @"SOFTWARE\Classes\Installer\Dependencies\{050d4fc8-5d48-4b8f-8972-47c82c46020f}",
                    Value = "Version",
                    Result = SearchResult.exists,
                    Variable = "MYCPP2013",
                }
                // The key for C++ 2015 didn't match the list value {3ee5e5bb-b7cc-4556-8861-a00a82977d6c}
                , new UtilRegistrySearch {
                    Root = Microsoft.Win32.RegistryHive.LocalMachine,
                    Key = @"SOFTWARE\Classes\Installer\Dependencies\{e46eca4f-393b-40df-9f49-076faf788d83}",
                    Value = "Version",
                    Result = SearchResult.exists,
                    Variable = "MYCPP2015",
                }
            );

            bootstrapper.IncludeWixExtension(WixExtension.Util);
            bootstrapper.Version = new Version("1.0.0.0");
            bootstrapper.UpgradeCode = new Guid("6f330b47-2577-43ad-9095-1861bb25844b");
            bootstrapper.Application = new SilentBootstrapperApplication();

            bootstrapper.PreserveTempFiles = true;

            bootstrapper.Build("MyProduct.exe");
        }

        static string BuildMsi() {
            var project = new Project("MyProduct",
                             new Dir(@"%ProgramFiles%\My Company\My Product",
                                 new File("Program.cs")));

            project.GUID = new Guid("6fe30b47-2577-43ad-9095-1861ba25889b");
            project.Platform = Platform.x64;
            //project.SourceBaseDir = "<input dir path>";
            //project.OutDir = "<output dir path>";

            return project.BuildMsi();
        }
    }
}
May 18, 2016 at 1:14 AM
I'm having trouble chaining from the C++ 2015 install to MyProduct.msi.
It works if I re-run the installer. No idea why it doesn't chain.
Testing was done on a clean Windows 7 VM.
May 19, 2016 at 3:02 AM
There is nothing obviously wrong. Is somehow this triggered by the nature of 'C++ 2015 install'? You may test this by just replacing it with something as simple as 'new ExePackage { Name = "Dummy", SourceFile = "Notepad.exe",...'