Пример #1
0
        /// <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);
        }
Пример #2
0
        /// <summary>
        /// Executes MSIExec on a .msi file
        /// </summary>
        /// <param name="sourceFile">Path the .msi file to use</param>
        /// <param name="mode">Mode of execution for MSIExec</param>
        /// <param name="otherArguments">Other arguments to pass to MSIExec.</param>
        /// <param name="expectedExitCode">Expected exit code</param>
        /// <returns>MSIExec exit code</returns>
        private static MSIExecReturnCode RunMSIExec(string sourceFile, MSIExecMode mode, string[] otherArguments, MSIExecReturnCode expectedExitCode, out string logFile)
        {
            MSIExec msiexec = new MSIExec();

            msiexec.Product        = sourceFile;
            msiexec.ExecutionMode  = mode;
            msiexec.OtherArguments = null != otherArguments?String.Join(" ", otherArguments) : null;

            msiexec.ExpectedExitCode = expectedExitCode;

            Result result = msiexec.Run();

            logFile = msiexec.LogFile;

            return((MSIExecReturnCode)result.ExitCode);
        }
Пример #3
0
        /// <summary>
        /// Executes MSIExec on a .msi file
        /// </summary>
        /// <param name="sourceFile">Path the .msi file to use</param>
        /// <param name="mode">Mode of execution for MSIExec</param>
        /// <param name="otherArguments">Other arguments to pass to MSIExec.</param>
        /// <param name="expectedExitCode">Expected exit code</param>
        /// <returns>MSIExec exit code</returns>
        private static MSIExecReturnCode RunMSIExec(string sourceFile, MSIExecMode mode, string[] otherArguments, MSIExecReturnCode expectedExitCode, out string logFile)
        {
            MSIExec msiexec = new MSIExec();
            msiexec.Product = sourceFile;
            msiexec.ExecutionMode = mode;
            msiexec.OtherArguments = null != otherArguments ? String.Join(" ", otherArguments) : null;
            msiexec.ExpectedExitCode = expectedExitCode;

            Result result = msiexec.Run();
            logFile = msiexec.LogFile;

            return (MSIExecReturnCode)result.ExitCode;
        }
        /// <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;
        }