ConsoleRun() public method

public ConsoleRun ( ) : int
return int
Exemplo n.º 1
0
        /// <summary>
        /// Installs the windows service. It uses InstallUtil.exe to complete the actual installation/uninstallation.
        /// During the run for the InstallUtil.exe console window is hidden.
        /// If any error occurred the console output is captured and embedded into the raised Exception object.
        /// </summary>
        /// <param name="serviceFile">The service file.</param>
        /// <param name="isInstalling">if set to <c>true</c> [is installing].</param>
        /// <param name="args">The additional InstallUtil.exe arguments.</param>
        /// <exception cref="T:System.Exception"></exception>
        /// <returns></returns>
        static public string InstallService(string serviceFile, bool isInstalling, string args = null)
        {
            var util = new ExternalTool
            {
                ExePath   = IO.Path.Combine(CurrentFrameworkDirectory, "InstallUtil.exe"),
                Arguments = string.Format("{1} \"{0}\" ", serviceFile, isInstalling ? "" : "/u") + args ?? ""
            };

            var    buf    = new StringBuilder();
            int    retval = util.ConsoleRun(line => buf.AppendLine(line));
            string output = buf.ToString();

            string logoLastLine = "Microsoft Corporation.  All rights reserved.";
            int    pos          = output.IndexOf(logoLastLine);

            if (pos != -1)
            {
                output = output.Substring(pos + logoLastLine.Length).Trim();
            }

            if (retval != 0)
            {
                throw new Exception(output);
            }

            return(output);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Applies digital signature to a file (e.g. msi, exe, dll) with MS <c>SignTool.exe</c> utility.
        /// </summary>
        /// <param name="fileToSign">The file to sign.</param>
        /// <param name="pfxFile">Specify the signing certificate in a file. If this file is a PFX with a password, the password may be supplied
        /// with the <c>password</c> parameter.</param>
        /// <param name="timeURL">The timestamp server's URL. If this option is not present (pass to null), the signed file will not be timestamped.
        /// A warning is generated if timestamping fails.</param>
        /// <param name="password">The password to use when opening the PFX file. Should be <c>null</c> if no password required.</param>
        /// <param name="optionalArguments">Extra arguments to pass to the <c>SignTool.exe</c> utility.</param>
        /// <param name="wellKnownLocations">The optional ';' separated list of directories where SignTool.exe can be located.
        /// If this parameter is not specified WixSharp will try to locate the SignTool in the built-in well-known locations (system PATH)</param>
        /// <returns>Exit code of the <c>SignTool.exe</c> process.</returns>
        ///
        /// <example>The following is an example of signing <c>Setup.msi</c> file.
        /// <code>
        /// WixSharp.CommonTasks.Tasks.DigitalySign(
        ///     "Setup.msi",
        ///     "MyCert.pfx",
        ///     "http://timestamp.verisign.com/scripts/timstamp.dll",
        ///     "MyPassword",
        ///     null);
        /// </code>
        /// </example>
        static public int DigitalySign(string fileToSign, string pfxFile, string timeURL, string password, string optionalArguments = null, string wellKnownLocations = null)
        {
            //"C:\Program Files\\Microsoft SDKs\Windows\v6.0A\bin\signtool.exe" sign /f "pfxFile" /p password /v "fileToSign" /t timeURL
            //string args = "sign /v /f \"" + pfxFile + "\" \"" + fileToSign + "\"";
            string args = "sign /v /f \"" + pfxFile + "\"";

            if (timeURL != null)
            {
                args += " /t \"" + timeURL + "\"";
            }
            if (password != null)
            {
                args += " /p \"" + password + "\"";
            }
            if (!optionalArguments.IsEmpty())
            {
                args += " " + optionalArguments;
            }

            args += " \"" + fileToSign + "\"";

            var tool = new ExternalTool
            {
                WellKnownLocations = wellKnownLocations ?? @"C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Bin",
                ExePath            = "signtool.exe",
                Arguments          = args
            };

            return(tool.ConsoleRun());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds the reference to the Visual Studio project.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <returns></returns>
        /// <exception cref="Exception">
        /// Project '{project.ProjectPath}' not found.
        /// or
        /// 'Heat' failure...
        /// </exception>
        public Harvester AddProject(VsProject project)
        {
            if (!System.IO.File.Exists(project.ProjectPath))
            {
                throw new Exception($"Project '{project.ProjectPath}' not found.");
            }

            var sourceDir  = project.BuildPath;
            var projectDir = project.ProjectPath.PathGetDirName();
            var targetDir  = project.TargetDir ?? this.targetDir;

            var output = this.project.OutDir.PathJoin($"{project.Name}.wxs");

            var tool = new ExternalTool
            {
                ExePath   = heat,
                Arguments = new[]
                {
                    $"project \"{project.ProjectPath}\"",
                    project.Binaries ? "-pog Binaries" : "",
                    project.Symbols ? "-pog Symbols" : "",
                    project.Documents  ? "-pog Documents" : "",
                    project.Satellites ? "-pog Satellites" : "",
                    project.Content ? "-pog Content" : "",
                    "-ag", "-sfrag",
                    $"-directoryid \"{targetDir}\"",
                    "-template fragment",
                    $"-platform AnyCPU",
                    $"-projectname \"{project.Name}\"",
                    $"-out \"{output}\""
                }.Join(" ")
            };

            // Note, all StdOut and StdErr will be printed by the `tool` anyway
            if (tool.ConsoleRun() != 0)
            {
                throw new Exception("'Heat' failure...");
            }

            var xml = XDocument.Load(output);

            foreach (var fragment in xml.Root.Elements())
            {
                this.project.AddXml("Wix", fragment.ToString());
            }

            // As intended the TargetDir for candle is the sourceDir
            this.project.CandleOptions +=
                $" -d\"{project.Name}.TargetDir\"=\"{sourceDir}\" " +
                $" -d\"{project.Name}.ProjectDir\"=\"{projectDir}\" ";
            components.Add(project);

            if (!Compiler.PreserveTempFiles)
            {
                System.IO.File.Delete(output);
            }

            return(this);
        }
Exemplo n.º 4
0
        static string ServiceDo(string action, string service, bool throwOnError)
        {
            var util = new ExternalTool {
                ExePath = "sc.exe", Arguments = action + " \"" + service + "\""
            };

            var buf    = new StringBuilder();
            int retval = util.ConsoleRun(line => buf.AppendLine(line));

            if (retval != 0 && throwOnError)
            {
                throw new Exception(buf.ToString());
            }
            return(buf.ToString());
        }