/// <inheritdoc/> public override void Extract(IBuilder builder, Stream stream, string?subDir = null) { EnsureFile(stream, msiPath => { try { using var engine = new CabEngine(); using var package = new MsiPackage(msiPath); package.ForEachCabinet(cabStream => { Handler.CancellationToken.ThrowIfCancellationRequested(); EnsureSeekable(cabStream, seekableStream => { // ReSharper disable once AccessToDisposedClosure engine.Unpack( new CabExtractorContext(builder, seekableStream, x => NormalizePath(package.Files[x], subDir), Handler.CancellationToken), fileFilter: package.Files.ContainsKey); }); }); } #region Error handling catch (Exception ex) when(ex is InstallerException or CabException) { // Wrap exception since only certain exception types are allowed throw new IOException(Resources.ArchiveInvalid, ex); } #endregion });
public void Should_Produce_MsiPackageXml() { var entity = new MsiPackage(@"Samples\SetupA.msi") { Payloads = new[] { @"Samples\setup1.dll", @"Samples\setup2.dll", }, Permanent = true, MsiProperties = "TRANSFORMS=[CommandArgs];GLOBAL=yes" }; var xml = entity.ToXml().First().ToString(); var expected = "<MsiPackage Permanent=\"yes\" SourceFile=\"Samples\\SetupA.msi\">\r\n" + " <Payload SourceFile=\"Samples\\setup1.dll\" />\r\n" + " <Payload SourceFile=\"Samples\\setup2.dll\" />\r\n" + " <MsiProperty Name=\"TRANSFORMS\" Value=\"[CommandArgs]\" />\r\n" + " <MsiProperty Name=\"GLOBAL\" Value=\"yes\" />\r\n" + "</MsiPackage>"; Assert.Equal(expected, xml); }
private void LoadMsiPackage() { try { string fileToOpen = string.Empty; if (openMsiFileDialog.ShowDialog() == DialogResult.OK) { fileToOpen = openMsiFileDialog.FileName; misPackage = new MsiPackage(fileToOpen); txtMSILocation.Text = fileToOpen; txtAppName.Text = misPackage.DisplayName; LoadTargetEnvironments(misPackage.TargetEnvironments.ToArray()); } } catch (Exception ex) { DisplayError(ex); } }
public bool VerifyPackage(string packagePath) { if (!MsiApi.VerifyPackage(packagePath)) { return(false); } var package = new MsiPackage(packagePath); if (!Guid.TryParse(package.UpgradeCode, out var upgradeCode)) { // is it possible and what should we do? return(false); } if (upgradeCode != UpgradeCode) { return(false); } // TODO: implement verification by signature return(true); }
static public void Main(string[] args) { 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" }; 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, MsiProperties = "PACKAGE_PROPERTY=[BundleVariable]" }, new MsiPackage(productMsi) { DisplayInternalUI = true }); bootstrapper.AboutUrl = "https://wixsharp.codeplex.com/"; 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.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.IncludeWixExtension(WixExtension.Util); // The code below sets WiX variables 'Netfx4FullVersion' and 'AdobeInstalled'. Note it has no affect on //the runtime behavior and use of 'FileSearch' and "RegistrySearch" only provided as an example. bootstrapper.AddWixFragment("Wix/Bundle", new UtilRegistrySearch { Root = RegistryHive.LocalMachine, Key = @"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.StringVariablesDefinition += "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"); //in real life scenarios suppression may need to be enabled (see SuppressWixMbaPrereqVars documentation) //bootstrapper.SuppressWixMbaPrereqVars = true; var setup = bootstrapper.Build("app_setup"); //--------------------------------------------------------- if (io.File.Exists(productMsi)) { io.File.Delete(productMsi); } if (io.File.Exists(crtMsi)) { io.File.Delete(crtMsi); } }
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); } }
public void Build() { Compiler.WixLocation = Path.Combine(Environment.ExpandEnvironmentVariables(@"%USERPROFILE%"), ".nuget", "packages", "wixsharp.wix.bin", "3.11.0", "tools", "bin"); var productId = Guid.NewGuid(); var projectBuilder = new ProjectBuilder("4.6.1", productId); var projectBuilderNet40 = new ProjectBuilder("4.0", productId); Console.WriteLine($"Building {nameof(MsiPackage)}s..."); var productMsi = projectBuilder.BuildMsi(); var productMsiNet40 = projectBuilderNet40.BuildMsi(); var productMsiPackage = new MsiPackage(productMsi) { DisplayInternalUI = true, InstallCondition = "VersionNT >= v6.0", Visible = false }; var productMsiPackageNet40 = new MsiPackage(productMsiNet40) { Id = "Computator.NET_Windows_XP", DisplayInternalUI = true, InstallCondition = "VersionNT < v6.0", Visible = false }; Console.WriteLine($"Creating final {nameof(Bundle)} object"); var bootstrapper = new Bundle("Computator.NET", productMsiPackageNet40, productMsiPackage) { IconFile = SharedProperties.IconLocation, DisableModify = "yes", Version = SharedProperties.Version, UpgradeCode = new Guid(SharedProperties.UpgradeCode), HelpUrl = SharedProperties.HelpUrl, AboutUrl = SharedProperties.AboutUrl, UpdateUrl = SharedProperties.UpdateUrl, HelpTelephone = SharedProperties.HelpTelephone, Manufacturer = SharedProperties.Company, /*Application = new SilentBootstrapperApplication() * { * LogoFile = SharedProperties.Logo, * LicensePath = SharedProperties.License, * }*/ Application = new LicenseBootstrapperApplication() { LogoFile = @"../Graphics/Installer/BootstrapperLogoFile65.png", //SharedProperties.LogoBmp, LicensePath = SharedProperties.License, //@"https://github.com/PawelTroka/Computator.NET/blob/master/LICENSE" }, SplashScreenSource = @"../Graphics/Installer/BootstrapperSplashScreen.bmp", //@"..\Graphics\computator.net-icon.png",//@"..\Graphics\Installer\InstallShield Computator.NET Theme\setup.gif", //PreserveTempFiles = true, }; Console.WriteLine($"Adding .NET dependencies..."); bootstrapper.Chain.InsertRange(0, new[] { new NetFx40WebInstaller().Build(bootstrapper), new NetFx461WebInstaller().Build(bootstrapper) }); Console.WriteLine($"Adding {nameof(PatchKnowledgeBase2468871)} for async-await support on Windows XP."); var patchKnowledgeBase2468871 = new PatchKnowledgeBase2468871(); var patchesForNet40 = patchKnowledgeBase2468871.Build(bootstrapper); bootstrapper.Chain.InsertRange(1, patchesForNet40); var finalPath = Path.Combine(SharedProperties.OutDir, "Computator.NET.Installer.exe"); Console.WriteLine($"Building final bundle '{finalPath}'"); bootstrapper.Build(finalPath); }