/// <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> /// Uninstalls the product and passes zero or more property settings. /// </summary> /// <param name="path">The path to the MSI to install.</param> /// <param name="expectedExitCode">The expected exit code.</param> /// <param name="properties">Zero or more properties to pass to the install.</param> /// <returns>The path to the log file.</returns> private string UninstallProductWithProperties(string path, MSIExec.MSIExecReturnCode expectedExitCode, params string[] properties) { return(RunMSIWithProperties(path, expectedExitCode, MSIExec.MSIExecMode.Uninstall, properties)); }