/// <summary> /// Ensures the packages built previously are uninstalled. /// </summary> protected override void UninstallItem(BuiltItem item) { MSIExec exec = new MSIExec(); exec.ExecutionMode = MSIExec.MSIExecMode.Uninstall; exec.OtherArguments = "IGNOREDEPENDENCIES=ALL"; exec.Product = item.Path; // Generate the log file name. string logFile = String.Format("{0}_{1:yyyyMMddhhmmss}_Cleanup_{2}.log", item.TestName, DateTime.UtcNow, Path.GetFileNameWithoutExtension(item.Path)); exec.LogFile = Path.Combine(Path.GetTempPath(), logFile); exec.Run(false); }
/// <summary> /// Runs msiexec on the given <paramref name="path"/> with zero or more property settings. /// </summary> /// <param name="path">The path to the MSI to run.</param> /// <param name="expectedExitCode">The expected exit code.</param> /// <param name="mode">The installation mode for the MSI.</param> /// <param name="properties">Zero or more properties to pass to the install.</param> /// <returns>The path to the log file.</returns> private string RunMSIWithProperties(string path, MSIExec.MSIExecReturnCode expectedExitCode, MSIExec.MSIExecMode mode, params string[] properties) { MSIExec exec = new MSIExec(); exec.ExecutionMode = mode; exec.ExpectedExitCode = expectedExitCode; exec.OtherArguments = null != properties?String.Join(" ", properties) : null; exec.Product = path; // Get the name of the calling method. StackTrace stack = new StackTrace(); string caller = stack.GetFrame(2).GetMethod().Name; // Generate the log file name. string logFile = String.Format("{0}_{1:yyyyMMddhhmmss}_{3}_{2}.log", caller, DateTime.UtcNow, Path.GetFileNameWithoutExtension(path), mode); exec.LogFile = Path.Combine(Path.GetTempPath(), logFile); exec.Run(); return(exec.LogFile); }
/// <summary> /// Runs msiexec on the given <paramref name="path"/> with zero or more property settings. /// </summary> /// <param name="path">The path to the MSI to run.</param> /// <param name="expectedExitCode">The expected exit code.</param> /// <param name="mode">The installation mode for the MSI.</param> /// <param name="properties">Zero or more properties to pass to the install.</param> /// <returns>The path to the log file.</returns> private string RunMSIWithProperties(string path, MSIExec.MSIExecReturnCode expectedExitCode, MSIExec.MSIExecMode mode, params string[] properties) { MSIExec exec = new MSIExec(); exec.ExecutionMode = mode; exec.ExpectedExitCode = expectedExitCode; exec.OtherArguments = null != properties ? String.Join(" ", properties) : null; exec.Product = path; // Get the name of the calling method. StackTrace stack = new StackTrace(); string caller = stack.GetFrame(2).GetMethod().Name; // Generate the log file name. string logFile = String.Format("{0}_{1:yyyyMMddhhmmss}_{3}_{2}.log", caller, DateTime.UtcNow, Path.GetFileNameWithoutExtension(path), mode); exec.LogFile = Path.Combine(Path.GetTempPath(), logFile); exec.Run(); return exec.LogFile; }