示例#1
0
        private bool GetVersionInformation()
        {
            this.LogTaskMessage(MessageImportance.Low, "Getting version information");
            RegistryKey vssKey;

            switch (this.SSVersion)
            {
            case "6d":
                vssKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\VisualStudio\6.0\Setup\Microsoft Visual SourceSafe Server") ??
                         Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\VisualStudio\6.0\Setup\Microsoft Visual SourceSafe");
                if (vssKey != null)
                {
                    string pathToSourceSafe = Convert.ToString(vssKey.GetValue("ProductDir"), CultureInfo.CurrentCulture);
                    this.fileName = Path.Combine(pathToSourceSafe, @"win32\ss.exe");
                    vssKey.Close();
                }

                break;

            case "2005":
                vssKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\VisualStudio\8.0\Setup\VS\VSS");
                if (vssKey != null)
                {
                    string pathToSourceSafe = Convert.ToString(vssKey.GetValue("ProductDir"), CultureInfo.CurrentCulture);
                    this.fileName = Path.Combine(pathToSourceSafe, "ss.exe");
                    vssKey.Close();
                }

                break;

            default:
                this.Log.LogError("Invalid SSVersion. Valid options are 6d or 2005");
                return(false);
            }

            this.shellWrapper = new ShellWrapper(this.fileName);

            if (this.Database != null)
            {
                this.shellWrapper.EnvironmentVariables.Add("SSDIR", this.Database.GetMetadata("FullPath"));
            }

            if (string.IsNullOrEmpty(this.UserName))
            {
                this.UserName = Environment.UserName;
            }

            this.shellWrapper.EnvironmentVariables.Add("SSUSER", this.UserName);
            if (!string.IsNullOrEmpty(this.UserPassword))
            {
                this.shellWrapper.EnvironmentVariables.Add("SSPWD", this.UserPassword);
            }

            this.LogTaskMessage(MessageImportance.Low, string.Format(CultureInfo.CurrentCulture, "Using UserName: {0} and Password: {1}", this.UserName, this.UserPassword));
            return(true);
        }
        public void ShellAdapterShallReturnTextFromCommand()
        {
            IShell            shellAdapter   = new ShellWrapper();
            CancellationToken cancelToken    = new CancellationToken();
            string            responseString = shellAdapter.Execute(
                command: "echo",
                args: new string[] { "hello world" }
                );

            Assert.Equal("hello world\n", responseString);
        }
示例#3
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <param name="action">The action.</param>
        /// <param name="options">The options.</param>
        /// <param name="lastOptions">The last options.</param>
        private void ExecuteCommand(string action, string options, string lastOptions)
        {
            this.itemSpec = string.Empty;
            if ((this.TaskAction != GetChangesetTaskAction) && (this.TaskAction != GetWorkingChangesetTaskAction) && (this.TaskAction != DeleteLabelTaskAction) && !this.DetermineItemSpec())
            {
                return;
            }

            string arguments = string.Format(CultureInfo.CurrentCulture, "{0} {1} {2}", action, this.itemSpec, options);

            if (string.IsNullOrEmpty(this.OverrideText) == false)
            {
                arguments += " /override:\"" + this.OverrideText + "\"";
            }

            if (this.Bypass)
            {
                arguments += " /bypass";
            }

            if (string.IsNullOrEmpty(this.Server) == false)
            {
                arguments += " /s:" + this.Server;
            }

            if (string.IsNullOrEmpty(this.Login) == false)
            {
                arguments += " /login:"******"/recursive", string.Empty);
            }

            arguments += " " + lastOptions;

            this.shellWrapper = new ShellWrapper(this.teamFoundationExe, arguments);
            if (string.IsNullOrEmpty(this.WorkingDirectory) == false)
            {
                this.shellWrapper.WorkingDirectory = this.WorkingDirectory;
                this.LogTaskMessage(MessageImportance.Low, string.Format(CultureInfo.CurrentCulture, "WorkingDirectory set to: {0}", this.WorkingDirectory));
            }

            this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "Executing {0} {1}", this.shellWrapper.Executable, this.shellWrapper.Arguments));
            this.ExitCode     = this.shellWrapper.Execute();
            this.returnOutput = this.shellWrapper.StandardOutput;
            this.LogTaskMessage(MessageImportance.Low, this.returnOutput);
            this.SwitchReturnValue(this.shellWrapper.StandardError.Trim());
        }
示例#4
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <param name="action">The action.</param>
        /// <param name="options">The options.</param>
        private void ExecuteCommand(string action, string options)
        {
            string arguments = String.Format(CultureInfo.CurrentCulture, "{0} {1}", action, options);

            this.shellWrapper = new ShellWrapper(this.teamFoundationExe, arguments);
            if (string.IsNullOrEmpty(this.WorkingDirectory) == false)
            {
                this.shellWrapper.WorkingDirectory = this.WorkingDirectory;
            }

            this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "Executing {0} with {1}", this.shellWrapper.Executable, arguments));
            this.ExitCode = this.shellWrapper.Execute();
            this.LogTaskMessage(MessageImportance.Low, this.shellWrapper.StandardOutput);
            this.SwitchReturnValue(this.shellWrapper.StandardError.Trim());
        }
示例#5
0
        private void AddComponent()
        {
            this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "Adding Component: {0} to Application: {1}", this.Path, this.ApplicationName));
            if (System.IO.File.Exists(this.Path) == false)
            {
                this.Log.LogError(string.Format(CultureInfo.CurrentCulture, "Path not found: {0}", this.Path));
                return;
            }

            if (this.IsValidAssemblyFile(this.Path))
            {
                this.shellWrapper = new ShellWrapper(System.IO.Path.Combine(System.IO.Path.Combine(this.pathToFramework, this.framework), "regsvcs.exe"), string.IsNullOrEmpty(this.ApplicationName) ? string.Format(CultureInfo.CurrentCulture, @"/quiet ""{0}""", this.Path) : string.Format(CultureInfo.CurrentCulture, @"/quiet ""{0}"" ""{1}""", this.Path, this.ApplicationName));
                this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "Executing {0} with {1}", this.shellWrapper.Executable, this.shellWrapper.Arguments));
                if (this.shellWrapper.Execute() != 0)
                {
                    this.Log.LogError("Shell execute failed: " + this.shellWrapper.StandardOutput);
                }
            }
        }
示例#6
0
        private void RemoveComponent()
        {
            this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "Removing Component: {0}", this.Path));
            if (System.IO.File.Exists(this.Path) == false)
            {
                this.Log.LogError(string.Format(CultureInfo.CurrentCulture, "Path not found: {0}", this.Path));
                return;
            }

            if (this.IsValidAssemblyFile(this.Path))
            {
                string args = string.Format(CultureInfo.CurrentCulture, @"/quiet /u ""{0}""", this.Path);
                this.shellWrapper = new ShellWrapper(System.IO.Path.Combine(System.IO.Path.Combine(this.pathToFramework, this.framework), "regsvcs.exe"), args);
                this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "Executing {0} with {1}", this.shellWrapper.Executable, this.shellWrapper.Arguments));
                if (this.shellWrapper.Execute() != 0)
                {
                    this.Log.LogError("Shell execute failed: " + this.shellWrapper.StandardOutput);
                }
            }
        }
示例#7
0
        private static ShellLinkObject GetLink(FileItem fi)
        {
            var pathOnly     = fi.Directory;
            var filenameOnly = fi.Name;

            var wrapper    = new ShellWrapper();
            var folder     = wrapper.GetFolder(pathOnly);
            var folderItem = folder.ParseName(filenameOnly);

            if (folderItem != null)
            {
                try
                {
                    return((ShellLinkObject)folderItem.GetLink);
                }
                catch
                {
                    return(null);
                }
            }

            return(null);
        }
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <param name="action">The action.</param>
        /// <param name="options">The options.</param>
        /// <param name="lastOptions">The last options.</param>
        private void ExecuteCommand(string action, string options, string lastOptions)
        {
            this.itemSpec = string.Empty;
            if ((this.TaskAction != GetChangesetTaskAction) && (this.TaskAction != GetWorkingChangesetTaskAction) && (this.TaskAction != DeleteLabelTaskAction) && !this.DetermineItemSpec())
            {
                return;
            }

            string arguments = string.Format(CultureInfo.CurrentCulture, "{0} {1} {2}", action, this.itemSpec, options);
            if (string.IsNullOrEmpty(this.OverrideText) == false)
            {
                arguments += " /override:\"" + this.OverrideText + "\"";
            }

            if (this.Bypass)
            {
                arguments += " /bypass";
            }

            if (string.IsNullOrEmpty(this.Server) == false)
            {
                arguments += " /s:" + this.Server;
            }

            if (string.IsNullOrEmpty(this.Login) == false)
            {
                arguments += " /login:"******"/recursive", string.Empty);
            }

            arguments += " " + lastOptions;

            this.shellWrapper = new ShellWrapper(this.teamFoundationExe, arguments);
            if (string.IsNullOrEmpty(this.WorkingDirectory) == false)
            {
                this.shellWrapper.WorkingDirectory = this.WorkingDirectory;
                this.LogTaskMessage(MessageImportance.Low, string.Format(CultureInfo.CurrentCulture, "WorkingDirectory set to: {0}", this.WorkingDirectory));
            }

            this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "Executing {0} {1}", this.shellWrapper.Executable, this.shellWrapper.Arguments));
            this.ExitCode = this.shellWrapper.Execute();
            this.returnOutput = this.shellWrapper.StandardOutput;
            this.LogTaskMessage(MessageImportance.Low, this.returnOutput);
            this.SwitchReturnValue(this.shellWrapper.StandardError.Trim());
        }
示例#9
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <param name="action">The action.</param>
        /// <param name="options">The options.</param>
        private void ExecuteCommand(string action, string options)
        {
            string arguments = String.Format(CultureInfo.CurrentCulture, "{0} {1}", action, options);

            this.shellWrapper = new ShellWrapper(this.teamFoundationExe, arguments);
            if (string.IsNullOrEmpty(this.WorkingDirectory) == false)
            {
                this.shellWrapper.WorkingDirectory = this.WorkingDirectory;
            }

            this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "Executing {0} with {1}", this.shellWrapper.Executable, arguments));
            this.ExitCode = this.shellWrapper.Execute();
            this.LogTaskMessage(MessageImportance.Low, this.shellWrapper.StandardOutput);
            this.SwitchReturnValue(this.shellWrapper.StandardError.Trim());
        }
        private bool GetVersionInformation()
        {
            this.LogTaskMessage(MessageImportance.Low, "Getting version information");
            RegistryKey vssKey;
            switch (this.SSVersion)
            {
                case "6d":
                    vssKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\VisualStudio\6.0\Setup\Microsoft Visual SourceSafe Server") ??
                             Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\VisualStudio\6.0\Setup\Microsoft Visual SourceSafe");
                    if (vssKey != null)
                    {
                        string pathToSourceSafe = Convert.ToString(vssKey.GetValue("ProductDir"), CultureInfo.CurrentCulture);
                        this.fileName = Path.Combine(pathToSourceSafe, @"win32\ss.exe");
                        vssKey.Close();
                    }

                    break;
                case "2005":
                    vssKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\VisualStudio\8.0\Setup\VS\VSS");
                    if (vssKey != null)
                    {
                        string pathToSourceSafe = Convert.ToString(vssKey.GetValue("ProductDir"), CultureInfo.CurrentCulture);
                        this.fileName = Path.Combine(pathToSourceSafe, "ss.exe");
                        vssKey.Close();
                    }

                    break;
                default:
                    this.Log.LogError("Invalid SSVersion. Valid options are 6d or 2005");
                    return false;
            }

            this.shellWrapper = new ShellWrapper(this.fileName);

            if (this.Database != null)
            {
                this.shellWrapper.EnvironmentVariables.Add("SSDIR", this.Database.GetMetadata("FullPath"));
            }   

            if (string.IsNullOrEmpty(this.UserName))
            {
                this.UserName = Environment.UserName;
            }

            this.shellWrapper.EnvironmentVariables.Add("SSUSER", this.UserName);
            if (!string.IsNullOrEmpty(this.UserPassword))
            {
                this.shellWrapper.EnvironmentVariables.Add("SSPWD", this.UserPassword);
            }

            this.LogTaskMessage(MessageImportance.Low, string.Format(CultureInfo.CurrentCulture, "Using UserName: {0} and Password: {1}", this.UserName, this.UserPassword));
            return true;
        }
示例#11
0
        private void ExecuteTargetSet(ITaskItem item)
        {
            string resolvedtargets = item.GetMetadata("Targets");

            if (resolvedtargets.EndsWith(";", StringComparison.OrdinalIgnoreCase))
            {
                resolvedtargets = resolvedtargets.Remove(resolvedtargets.Length - 1, 1);
            }

            this.LogTaskMessage(MessageImportance.High, string.Format(CultureInfo.CurrentCulture, "Building Target Set: {0} - {1}", item.ItemSpec, resolvedtargets));
            string properties = item.GetMetadata("Properties");

            if (!string.IsNullOrEmpty(properties))
            {
                properties = " /p:" + properties;
            }

            if (!string.IsNullOrEmpty(this.AdditionalProperties))
            {
                properties += " /p:" + this.AdditionalProperties;
            }

            string projectFile = this.ProjectFile == null ? this.BuildEngine.ProjectFileOfTaskNode : this.ProjectFile.ItemSpec;

            string logginginfo = string.Empty;
            string logfileName = item.GetMetadata("LogFileName");

            if (string.IsNullOrEmpty(logfileName))
            {
                logfileName = item.ItemSpec + ".txt";
            }
            else
            {
                string logfilePath = item.GetMetadata("LogFilePath");
                if (!string.IsNullOrEmpty(logfilePath))
                {
                    if (!Directory.Exists(logfilePath))
                    {
                        Directory.CreateDirectory(logfilePath);
                    }

                    logfileName = System.IO.Path.Combine(logfilePath, logfileName);
                }
            }

            if (this.MultiLog)
            {
                // note there is a bug in MSBuild loggers whereby the logger will append whenever it sees append in the arguments, so you can's say append=false.
                string append = string.Empty;
                if (this.multiLogAppend)
                {
                    append = "append=true;";
                }

                logginginfo = string.Format(CultureInfo.CurrentCulture, "/l:FileLogger,Microsoft.Build.Engine;{0}verbosity={1};logfile=\"{2}\"", append, this.MultiLogVerbosity, logfileName);
            }

            var exec = new ShellWrapper("msbuild.exe", "\"" + projectFile + "\"" +
                                        " /v:" + (this.MultiLog ? this.MultiLogResponseVerbosity : this.LogVerbosity) +
                                        " /t:" + resolvedtargets + properties + this.multiprocparameter +
                                        " /nr:" + this.nodereuse +
                                        (this.NoLogo ? " /nologo" : string.Empty) + " " + logginginfo);

            if (string.IsNullOrEmpty(this.WorkingDirectory) == false)
            {
                exec.WorkingDirectory = this.WorkingDirectory;
            }

            this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "Executing {0} {1}", exec.Executable, exec.Arguments));

            // stderr is logged as errors
            exec.ErrorDataReceived += (sender, e) =>
            {
                if (e.Data != null)
                {
                    this.Log.LogError(e.Data);
                }
            };

            exec.OutputDataReceived += (sender, e) =>
            {
                if (e.Data != null)
                {
                    if (this.Log != null)
                    {
                        try
                        {
                            this.Log.LogMessage(MessageImportance.Normal, e.Data);
                        }
                        catch
                        {
                            // do nothing. We have a race condition here with the MSBuild host being killed and the logging still trying to occur.
                        }
                    }
                }
            };

            // execute the process
            int exitCode = exec.Execute();

            if (exitCode != 0)
            {
                string errorFile = string.Empty;
                if (this.MultiLog)
                {
                    errorFile = "Additional information may be found in: " + logfileName;
                }

                this.Log.LogError(string.Format(CultureInfo.InvariantCulture, "Error Code: {0}. {1}", exitCode, errorFile));

                if (this.MultiLog && this.MultiLogOpenOnFailure)
                {
                    FileInfo f = new FileInfo(this.BuildEngine.ProjectFileOfTaskNode);
                    System.Diagnostics.Process.Start(System.IO.Path.Combine(f.Directory.FullName, logfileName));
                }
            }
        }
示例#12
0
        private void AddComponent()
        {
            this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "Adding Component: {0} to Application: {1}", this.Path, this.ApplicationName));
            if (System.IO.File.Exists(this.Path) == false)
            {
                this.Log.LogError(string.Format(CultureInfo.CurrentCulture, "Path not found: {0}", this.Path));
                return;
            }

            if (this.IsValidAssemblyFile(this.Path))
            {
                this.shellWrapper = new ShellWrapper(System.IO.Path.Combine(System.IO.Path.Combine(this.pathToFramework, this.framework), "regsvcs.exe"), string.IsNullOrEmpty(this.ApplicationName) ? string.Format(CultureInfo.CurrentCulture, "/quiet {0}", this.Path) : string.Format(CultureInfo.CurrentCulture, @"/quiet {0} ""{1}""", this.Path, this.ApplicationName));
                this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "Executing {0} with {1}", this.shellWrapper.Executable, this.shellWrapper.Arguments));
                if (this.shellWrapper.Execute() != 0)
                {
                    this.Log.LogError("Shell execute failed: " + this.shellWrapper.StandardOutput);
                    return;
                }
            }
        }
示例#13
0
        private void RemoveComponent()
        {
            this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "Removing Component: {0}", this.Path));
            if (System.IO.File.Exists(this.Path) == false)
            {
                this.Log.LogError(string.Format(CultureInfo.CurrentCulture, "Path not found: {0}", this.Path));
                return;
            }

            if (this.IsValidAssemblyFile(this.Path))
            {
                string args = string.Format(CultureInfo.CurrentCulture, @"/quiet /u ""{0}""", this.Path);
                this.shellWrapper = new ShellWrapper(System.IO.Path.Combine(System.IO.Path.Combine(this.pathToFramework, this.framework), "regsvcs.exe"), args);
                this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "Executing {0} with {1}", this.shellWrapper.Executable, this.shellWrapper.Arguments));
                if (this.shellWrapper.Execute() != 0)
                {
                    this.Log.LogError("Shell execute failed: " + this.shellWrapper.StandardOutput);
                }
            }
        }
        private void ExecuteTargetSet(ITaskItem item)
        {
            string resolvedtargets = item.GetMetadata("Targets");
            if (resolvedtargets.EndsWith(";", StringComparison.OrdinalIgnoreCase))
            {
                resolvedtargets = resolvedtargets.Remove(resolvedtargets.Length - 1, 1);
            }

            this.LogTaskMessage(MessageImportance.High, string.Format(CultureInfo.CurrentCulture, "Building Target Set: {0} - {1}", item.ItemSpec, resolvedtargets));
            string properties = item.GetMetadata("Properties");
            if (!string.IsNullOrEmpty(properties))
            {
                properties = " /p:" + properties;
            }

            if (!string.IsNullOrEmpty(this.AdditionalProperties))
            {
                properties += " /p:" + this.AdditionalProperties;
            }

            string projectFile = this.ProjectFile == null ? this.BuildEngine.ProjectFileOfTaskNode : this.ProjectFile.ItemSpec;
            
            string logginginfo = string.Empty;
            string logfileName = item.GetMetadata("LogFileName");
            if (string.IsNullOrEmpty(logfileName))
            {
                logfileName = item.ItemSpec + ".txt";
            }
            else
            {
                string logfilePath = item.GetMetadata("LogFilePath");
                if (!string.IsNullOrEmpty(logfilePath))
                {
                    if (!Directory.Exists(logfilePath))
                    {
                        Directory.CreateDirectory(logfilePath);
                    }

                    logfileName = System.IO.Path.Combine(logfilePath, logfileName);
                }
            }

            if (this.MultiLog)
            {
                // note there is a bug in MSBuild loggers whereby the logger will append whenever it sees append in the arguments, so you can's say append=false.
                string append = string.Empty;
                if (this.multiLogAppend)
                {
                    append = "append=true;";
                }

                logginginfo = string.Format(CultureInfo.CurrentCulture, "/l:FileLogger,Microsoft.Build.Engine;{0}verbosity={1};logfile=\"{2}\"", append, this.MultiLogVerbosity, logfileName);
            }

            var exec = new ShellWrapper("msbuild.exe", "\"" + projectFile + "\" /v:" + this.MultiLogResponseVerbosity + " /t:" + resolvedtargets + properties + this.multiprocparameter + " /nr:" + this.nodereuse + " " + logginginfo);
            if (string.IsNullOrEmpty(this.WorkingDirectory) == false)
            {
                exec.WorkingDirectory = this.WorkingDirectory;
            }

            this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "Executing {0} {1}", exec.Executable, exec.Arguments));

            // stderr is logged as errors
            exec.ErrorDataReceived += (sender, e) =>
                                          {
                                              if (e.Data != null)
                                              {
                                                  this.Log.LogError(e.Data);
                                              }
                                          };

            exec.OutputDataReceived += (sender, e) =>
                {
                    if (e.Data != null)
                    {
                        if (this.Log != null)
                        {
                            try
                            {
                                this.Log.LogMessage(MessageImportance.Normal, e.Data);
                            }
                            catch
                            {
                                // do nothing. We have a race condition here with the MSBuild host being killed and the logging still trying to occur.
                            }
                        }
                    }
                };

            // execute the process
            int exitCode = exec.Execute();
            if (exitCode != 0)
            {
                string errorFile = string.Empty;
                if (this.MultiLog)
                {
                    errorFile = "Additional information may be found in: " + logfileName;
                }

                this.Log.LogError(string.Format(CultureInfo.InvariantCulture, "Error Code: {0}. {1}", exitCode, errorFile));

                if (this.MultiLog && this.MultiLogOpenOnFailure)
                {
                    FileInfo f = new FileInfo(this.BuildEngine.ProjectFileOfTaskNode);
                    System.Diagnostics.Process.Start(System.IO.Path.Combine(f.Directory.FullName, logfileName));
                }
            }
        }