Пример #1
0
    static public void Main()
    {
        string productMsi = BuildMainMsi();
        string crtMsi     = BuildCrtMsi();

        //---------------------------------------------------------

        var msiOnlinePackage = new MsiPackage(crtMsi) //demo for downloadable msi package
        {
            Vital             = true,
            Compressed        = false,
            DisplayInternalUI = true,
            DownloadUrl       = @"https://dl.dropboxusercontent.com/....../CRT.msi"
        };

        // Compiler.AutoGeneration.SuppressForBundleUndefinedIds = false;
        // Compiler.AutoGeneration.LegacyDefaultIdAlgorithm = false;

        var bootstrapper =
            new Bundle("My Product",
                       new PackageGroupRef("NetFx40Web"),
                       //new ExePackage(@"..\redist\dotNetFx40_Full_x86_x64.exe") //just a demo sample
                       //{
                       //     Name = "Microsoft .NET Framework 4.0",
                       //     InstallCommand = "/passive /norestart",
                       //     Permanent = true,
                       //     Vital = true,
                       //     DetectCondition = "Netfx4FullVersion AND (NOT VersionNT64 OR Netfx4x64FullVersion)",
                       //     Compressed = true
                       //},

                       //msiOnlinePackage, //just a demo sample

                       new MsiPackage(crtMsi)
        {
            DisplayInternalUI = true,
            Visible           = true,
            MsiProperties     = "PACKAGE_PROPERTY=[BundleVariable]"
        },
                       new MsiPackage(productMsi)
        {
            DisplayInternalUI = true,
            Payloads          = new[] { "script.dll".ToPayload() }
        });

        bootstrapper.AboutUrl             = "https://github.com/oleg-shilo/wixsharp/";
        bootstrapper.IconFile             = "app_icon.ico";
        bootstrapper.Version              = Tasks.GetVersionFromFile(productMsi); //will extract "product version"
        bootstrapper.UpgradeCode          = new Guid("6f330b47-2577-43ad-9095-1861bb25889b");
        bootstrapper.Application.LogoFile = "logo.png";
        bootstrapper.Application.Payloads = new[] { "logo.png".ToPayload() };

        // adding themes
        // var themes = new[]
        //     {
        //         new Payload("managedsetup.wxl") { Name = "1033\thm.wxl" }
        //     };
        // bootstrapper.Application.Payloads = themes;

        bootstrapper.Application.LicensePath = "licence.html"; //HyperlinkLicense app with embedded license file
        bootstrapper.Application.LicensePath = "licence.rtf";  //RtfLicense app with embedded license file
        // bootstrapper.Application.LicensePath = "http://opensource.org/licenses/MIT"; //HyperlinkLicense app with online license file
        // bootstrapper.Application.LicensePath = null; //HyperlinkLicense app with no license

        bootstrapper.Application.AttributesDefinition = "ShowVersion=yes; ShowFilesInUse=yes";
        bootstrapper.Include(WixExtension.Util);

        bootstrapper.IncludeWixExtension(@"WixDependencyExtension.dll", "dep", "http://schemas.microsoft.com/wix/DependencyExtension");
        bootstrapper.AttributesDefinition = "{dep}ProviderKey=01234567-8901-2345-6789-012345678901";

        // The code below sets WiX variables 'Netfx4FullVersion' and 'AdobeInstalled'. Note it has no affect on
        //the runtime behaviour and 'FileSearch' and "RegistrySearch" are only provided as an example.
        bootstrapper.AddWixFragment("Wix/Bundle",
                                    new UtilRegistrySearch
        {
            Root     = RegistryHive.LocalMachine,
            Key      = @"SOFTWARE\Microsoft\Net Framework Setup\NDP\v4\Full",
            Value    = "Version",
            Variable = "Netfx4FullVersion"
        },
                                    new UtilFileSearch
        {
            Path     = @"[ProgramFilesFolder]Adobe\adobe.exe",
            Result   = SearchResult.exists,
            Variable = "AdobeInstalled"
        });

        // bootstrapper.AddXml("Wix/Bundle", "<Log PathVariable=\"LogFileLocation\"/>");

        bootstrapper.AddXmlElement("Wix/Bundle", "Log", "PathVariable=LogFileLocation");
        bootstrapper.Variables = new[] { new Variable("LogFileLocation", @"C:\temp\setup.log")
                                         {
                                             Overridable = true
                                         } };
        // or
        // bootstrapper.Variables = "BundleVariable=333".ToStringVariables();
        // bootstrapper.Variables = Variables.ToStringVariables("BundleVariable=333");

        bootstrapper.PreserveTempFiles = true;

        // Add MspPackage manually (demo only).
        // In the future releases the direct support for MspPackage element will be added.
        // bootstrapper.WixSourceGenerated += (doc) => doc.FindSingle("Chain")
        //                                                .AddElement("MspPackage",
        //                                                            "SourceFile=Patch.msp; Slipstream=no");

        // bootstrapper.WixSourceGenerated += doc => doc.FindSingle("WixStandardBootstrapperApplication")
        //                                              .AddAttributes("ShowVersion=yes; ShowFilesInUse=no");

        //in real life scenarios suppression may need to be enabled (see SuppressWixMbaPrereqVars documentation)
        //bootstrapper.SuppressWixMbaPrereqVars = true;
        var setup = bootstrapper.Build("app_setup");

        Console.WriteLine(setup);
        //---------------------------------------------------------

        if (io.File.Exists(productMsi))
        {
            io.File.Delete(productMsi);
        }
        if (io.File.Exists(crtMsi))
        {
            io.File.Delete(crtMsi);
        }
    }
Пример #2
0
        static void Main(string[] args)
        {
            var productProj =
                new ManagedProject("My Product",
                                   new Dir("[INSTALLDIR]",
                                           new Dir("bin", new File("ui.config")),
                                           new Dir("obj", new File("ui.config"))
                                           ),
                                   new RegValue(RegistryHive.LocalMachine, @"SOFTWARE\My Product", "test", "testvalue"),
                                   new RemoveRegistryKey(RegistryHive.LocalMachine, @"Software\My Product"))
            {
                InstallPrivileges = InstallPrivileges.elevated,
                InstallScope      = InstallScope.perMachine,
                GUID = new Guid("6a330b47-2577-43ad-9095-1861bb25889a")
            };


            //productProj.Load += (SetupEventArgs e) => {
            //    e.Session.Property("INSTALLDIR");
            //};

            string productMsi = productProj.BuildMsi();

            //------------------------------------

            var bootstrapper =
                new Bundle("TestInstall",
                           new PackageGroupRef("NetFx47Redist"),
                           new MsiPackage(productMsi)
            {
                Id = "TestInstall",
                DisplayInternalUI = false,
                MsiProperties     = @"USERINPUT=[UserInput];INSTALLDIR=[InstallPath]"
            });

            bootstrapper.WxsFiles.Add("Net47.wxs");
            bootstrapper.Include(WixExtension.Util);
            //bootstrapper.Include(WixExtension.NetFx);
            bootstrapper.AddXmlElement("Wix/Bundle", "Log", "PathVariable=LogFileLocation");
            bootstrapper.Variables = new[] {
                new Variable("LogFileLocation", $"D:\\log.txt")
                {
                    Overridable = true
                },
                new Variable("UserInput", "<none>"),
                new Variable("InstallPath", "[ProgramFiles6432Folder]\\My Company\\My Product"),
            };

            bootstrapper.AddWixFragment("Wix/Bundle",
                                        new UtilRegistrySearch {
                Root     = RegistryHive.LocalMachine,
                Key      = @"SOFTWARE\Microsoft\Net Framework Setup\NDP\v4\Full",
                Value    = "Version",
                Variable = "Netfx4FullVersion",
                Result   = SearchResult.value
            });
            bootstrapper.Version     = new Version("1.0.0.0");
            bootstrapper.UpgradeCode = new Guid("6a330b47-2577-43ad-9095-1861bb25889a");
            bootstrapper.IconFile    = @"Res\test.ico";
            // You can also use System.Reflection.Assembly.GetExecutingAssembly().Location instead of "%this%"
            // Note, passing BootstrapperCore.config is optional and if not provided the default BootstrapperCore.config
            // will be used. The content of the default BootstrapperCore.config can be accessed via
            // ManagedBootstrapperApplication.DefaultBootstrapperCoreConfigContent.
            //
            // Note that the DefaultBootstrapperCoreConfigContent may not be suitable for all build and runtime scenarios.
            // In such cases you may need to use custom BootstrapperCore.config as demonstrated below.
            bootstrapper.Application = new ManagedBootstrapperApplication(typeof(App).Assembly.Location);
            ManagedBootstrapperApplication.DefaultBootstrapperCoreConfigContent = @"<?xml version=""1.0"" encoding=""utf-8"" ?><configuration><configSections><sectionGroup name=""wix.bootstrapper"" type=""Microsoft.Tools.WindowsInstallerXml.Bootstrapper.BootstrapperSectionGroup, BootstrapperCore""><section name=""host"" type=""Microsoft.Tools.WindowsInstallerXml.Bootstrapper.HostSection, BootstrapperCore"" /></sectionGroup></configSections><startup useLegacyV2RuntimeActivationPolicy=""true""><supportedRuntime version=""v4.0"" /></startup><wix.bootstrapper><host assemblyName=""WixBootstrapperWPF"">      <supportedFramework version=""v4\Full"" /><supportedFramework version=""v4\Client"" /></host></wix.bootstrapper></configuration>";
            //var asse = ass.GetExecutingAssembly();
            //var names = asse.GetManifestResourceNames();
            //using (io.StreamReader reader = new io.StreamReader(asse.GetManifestResourceStream("ui.config"))) {
            //    ManagedBootstrapperApplication.DefaultBootstrapperCoreConfigContent = reader.ReadToEnd();
            //}

            bootstrapper.PreserveTempFiles        = true;
            bootstrapper.SuppressWixMbaPrereqVars = true;

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