/// <summary> /// Gets whether the product defined by the package <paramref name="path"/> is installed. /// </summary> /// <param name="path">The path to the package to test.</param> /// <returns>True if the package is installed; otherwise, false.</returns> public static bool IsPackageInstalled(string path) { string productCode; if (!PathsToProductCodes.TryGetValue(path, out productCode)) { productCode = MsiUtils.GetMSIProductCode(path); PathsToProductCodes.Add(path, productCode); } return(MsiUtils.IsProductInstalled(productCode)); }
public void DependencyExtension_UninstallDependencyOverrideSpecific() { string packageA = BuildPackage("A", null); string packageB = BuildPackage("B", null); MSIExec.InstallProduct(packageA, MSIExec.MSIExecReturnCode.SUCCESS); MSIExec.InstallProduct(packageB, MSIExec.MSIExecReturnCode.SUCCESS); // Now attempt the uninstall of dependency package A. string productCode = MsiUtils.GetMSIProductCode(packageB); string ignoreDependencies = String.Concat("IGNOREDEPENDENCIES=", productCode); UninstallProductWithProperties(packageA, MSIExec.MSIExecReturnCode.SUCCESS, ignoreDependencies); MSIExec.UninstallProduct(packageB, MSIExec.MSIExecReturnCode.SUCCESS); }
public void Burn_ValidateMultipleSourcePaths() { // Build the package. string packageA = this.GetPackageA().Output; string packageA_Directory = Path.GetDirectoryName(packageA); string packageA_ProductCode = MsiUtils.GetMSIProductCode(packageA); // Build the bundle. string bundleA = this.GetBundleA().Output; // Install the bundle. BundleInstaller installerA = new BundleInstaller(this, bundleA).Install(); Assert.True(MsiVerifier.IsPackageInstalled(packageA)); // Copy the package using the bundle package name. ProductInstallation product = new ProductInstallation(packageA_ProductCode, null, UserContexts.Machine); string packageA_Copy = Path.Combine(packageA_Directory, product.AdvertisedPackageName); File.Copy(packageA, packageA_Copy); this.TestArtifacts.Add(new FileInfo(packageA_Copy)); // Repair and recache the MSI. MSIExec.InstallProduct(packageA_Copy, MSIExec.MSIExecReturnCode.SUCCESS, "REINSTALL=ALL REINSTALLMODE=vomus"); Assert.True(MsiVerifier.IsPackageInstalled(packageA)); // Check that the source contains both the original and burn cached paths. SourceList sources = product.SourceList; Assert.Equal(2, sources.Count); // Attempt to uninstall bundleA. installerA.Uninstall(); Assert.False(MsiVerifier.IsPackageInstalled(packageA)); this.Complete(); }
/// <summary> /// Gets whether the product defined by the package <paramref name="productCode"/> is installed. /// </summary> /// <param name="path">The product code of the package to test.</param> /// <returns>True if the package is installed; otherwise, false.</returns> public static bool IsProductInstalled(string productCode) { return(MsiUtils.IsProductInstalled(productCode)); }
/// <summary> /// Uninstalls all the payload items in a layout /// </summary> public void UninstallAllPayloads() { // loop thru all the items in a layout and uninstall them. foreach (WixTest.Burn.OM.WixAuthoringOM.Bundle.Chain.Package package in m_Layout.Wix.Bundle.Chain.Packages) { Type t = package.GetType(); switch (t.FullName) { case "WixTest.Burn.OM.WixAuthoringOM.Bundle.Chain.ExePackageElement": // run the exe with the UninstallCommandLine // hopefully the Exe does the right thing // per-user installs that were performed by another user will probably not be removed properly. string exeFile = null; if (!String.IsNullOrEmpty(package.SourceFilePathT)) { exeFile = package.SourceFilePathT; } else if (m_Layout != null && (!String.IsNullOrEmpty(m_Layout.LayoutFolder)) && (!String.IsNullOrEmpty(((WixTest.Burn.OM.WixAuthoringOM.Bundle.Chain.ExePackageElement)package).Name))) { exeFile = Path.Combine(m_Layout.LayoutFolder, ((WixTest.Burn.OM.WixAuthoringOM.Bundle.Chain.ExePackageElement)package).Name); } if (!String.IsNullOrEmpty(exeFile)) { Process proc = new Process(); proc.StartInfo.Arguments = ((WixTest.Burn.OM.WixAuthoringOM.Bundle.Chain.ExePackageElement)package).UninstallCommand; proc.StartInfo.FileName = exeFile; proc.Start(); proc.WaitForExit(); } else { System.Diagnostics.Trace.TraceError("Unable to find Exe to uninstall: {0}", ((WixTest.Burn.OM.WixAuthoringOM.Bundle.Chain.ExePackageElement)package).Name); } break; case "WixTest.Burn.OM.WixAuthoringOM.Bundle.Chain.MsiPackageElement": // unintall the Msi from the SourceFile if it is set // otherwise, use the Msi in the layout if it can be found string msiFile = null; if (!String.IsNullOrEmpty(package.SourceFilePathT)) { msiFile = package.SourceFilePathT; } else if (m_Layout != null && (!String.IsNullOrEmpty(m_Layout.LayoutFolder)) && (!String.IsNullOrEmpty(((WixTest.Burn.OM.WixAuthoringOM.Bundle.Chain.MsiPackageElement)package).Name))) { msiFile = Path.Combine(m_Layout.LayoutFolder, ((WixTest.Burn.OM.WixAuthoringOM.Bundle.Chain.MsiPackageElement)package).Name); } if (!String.IsNullOrEmpty(msiFile)) { MsiUtils.RemoveMSI(msiFile); } else { System.Diagnostics.Trace.TraceError("Unable to find Msi to uninstall: {0}", ((WixTest.Burn.OM.WixAuthoringOM.Bundle.Chain.MsiPackageElement)package).Name); } break; case "WixTest.Burn.OM.WixAuthoringOM.Bundle.Chain.MspPackageElement": string mspFile = null; if (!String.IsNullOrEmpty(package.SourceFilePathT)) { mspFile = package.SourceFilePathT; } else if (m_Layout != null && (!String.IsNullOrEmpty(m_Layout.LayoutFolder)) && (!String.IsNullOrEmpty(((WixTest.Burn.OM.WixAuthoringOM.Bundle.Chain.MspPackageElement)package).Name))) { mspFile = Path.Combine(m_Layout.LayoutFolder, ((WixTest.Burn.OM.WixAuthoringOM.Bundle.Chain.MspPackageElement)package).Name); } if (!String.IsNullOrEmpty(mspFile)) { MsiUtils.RemovePatchFromProducts(MsiUtils.GetPatchCode(mspFile), MsiUtils.GetTargetProductCodes(mspFile)); } else { System.Diagnostics.Trace.TraceError("Unable to find Msp file to uninstall: {0}", ((WixTest.Burn.OM.WixAuthoringOM.Bundle.Chain.MspPackageElement)package).Name); } break; // BUGBUG TODO: handle Item Groups (i.e. Patches) once support for testing those is enabled in the LayoutManager default: System.Diagnostics.Trace.TraceError("Unknown item type to uninstall. type = {0}", t.FullName); break; } } }
public void Burn_InstallPatchBundle() { const string expectedVersion = "1.0.1.0"; // Build the packages. string packageA1 = new PackageBuilder(this, "A") { Extensions = Extensions }.Build().Output; string packageA2 = new PackageBuilder(this, "A") { Extensions = Extensions, PreprocessorVariables = new Dictionary <string, string>() { { "Version", expectedVersion } }, NeverGetsInstalled = true }.Build().Output; string packageB = new PackageBuilder(this, "B") { Extensions = Extensions }.Build().Output; string patchA = new PatchBuilder(this, "PatchA") { PreprocessorVariables = new Dictionary <string, string>() { { "Version", expectedVersion } }, TargetPath = packageA1, UpgradePath = packageA2 }.Build().Output; // Create the named bind paths to the packages. Dictionary <string, string> bindPaths = new Dictionary <string, string>(); bindPaths.Add("packageA", packageA1); bindPaths.Add("packageB", packageB); bindPaths.Add("patchA", patchA); // Build the bundles. string bundleF = new BundleBuilder(this, "BundleF") { BindPaths = bindPaths, Extensions = Extensions }.Build().Output; string bundleG = new BundleBuilder(this, "BundleG") { BindPaths = bindPaths, Extensions = Extensions }.Build().Output; // Install the base bundle and make sure all packages are installed. BundleInstaller installerF = new BundleInstaller(this, bundleF).Install(); Assert.IsTrue(MsiVerifier.IsPackageInstalled(packageA1)); Assert.IsTrue(MsiVerifier.IsPackageInstalled(packageB)); // Install patch bundle and make sure all packages are installed. BundleInstaller installerG = new BundleInstaller(this, bundleG).Install(); Assert.IsTrue(MsiVerifier.IsPackageInstalled(packageA1)); Assert.IsTrue(MsiVerifier.IsPackageInstalled(packageB)); Assert.IsTrue(MsiUtils.IsPatchInstalled(patchA)); // Uninstall the base bundle and make sure all packages are uninstalled. installerF.Uninstall(); Assert.IsFalse(MsiVerifier.IsPackageInstalled(packageA1)); Assert.IsFalse(MsiVerifier.IsPackageInstalled(packageB)); Assert.IsFalse(MsiUtils.IsPatchInstalled(patchA)); this.CleanTestArtifacts = true; }
public void Burn_InstallUpgradeSlipstreamBundle() { const string expectedVersion1 = "1.0.0.0"; const string expectedVersion2 = "1.0.1.0"; // Build the packages. string packageA = new PackageBuilder(this, "A") { Extensions = Extensions }.Build().Output; string packageA1 = new PackageBuilder(this, "A") { Extensions = Extensions, PreprocessorVariables = new Dictionary <string, string>() { { "Version", expectedVersion2 } }, NeverGetsInstalled = true }.Build().Output; string patchA = new PatchBuilder(this, "PatchA") { PreprocessorVariables = new Dictionary <string, string>() { { "Version", expectedVersion2 } }, TargetPath = packageA, UpgradePath = packageA1 }.Build().Output; // Create the named bind paths to the packages. Dictionary <string, string> bindPaths = new Dictionary <string, string>(); bindPaths.Add("packageA", packageA); bindPaths.Add("patchA", patchA); // Build the bundles. string bundleA = new BundleBuilder(this, "BundleA") { BindPaths = bindPaths, Extensions = Extensions }.Build().Output; string bundleC = new BundleBuilder(this, "BundleC") { BindPaths = bindPaths, Extensions = Extensions, PreprocessorVariables = new Dictionary <string, string>() { { "Version", expectedVersion2 } } }.Build().Output; // Install the base bundle and make sure it's installed. BundleInstaller installerA = new BundleInstaller(this, bundleA).Install(); Assert.IsTrue(MsiVerifier.IsPackageInstalled(packageA)); using (RegistryKey root = this.GetTestRegistryRoot()) { string actualVersion = root.GetValue("Version") as string; Assert.AreEqual(expectedVersion1, actualVersion); } // Install the upgrade bundle with a slipstreamed patch and make sure the patch is installed. // SFBUG:3387046 - Uninstalling bundle registers a dependency on a package BundleInstaller installerC = new BundleInstaller(this, bundleC).Install(); Assert.IsTrue(MsiUtils.IsPatchInstalled(patchA)); // BundleC doesn't carry the EXE, so make sure it's removed. using (RegistryKey root = this.GetTestRegistryRoot()) { Assert.IsNull(root.GetValue("Version")); } // Repair the upgrade bundle to make sure it does not prompt for source. // SFBUG:3386927 - MSIs get removed from cache during upgrade installerC.Repair(); // Uninstall the slipstream bundle and make sure both packages are uninstalled. installerC.Uninstall(); Assert.IsFalse(MsiUtils.IsPatchInstalled(patchA)); Assert.IsFalse(MsiVerifier.IsPackageInstalled(packageA)); this.CleanTestArtifacts = true; }
/// <summary> /// Gets whether the product defined by the package <paramref name="path"/> is installed. /// </summary> /// <param name="path">The path to the package to test.</param> /// <returns>True if the package is installed; otherwise, false.</returns> private bool IsPackageInstalled(string path) { string productCode = MsiUtils.GetMSIProductCode(path); return(MsiUtils.IsProductInstalled(productCode)); }