Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NCoverTask"/> class.
        /// </summary>
        public NCoverTask()
        {
            _version          = "1.5";
            _commandLineExe   = string.Empty;
            _commandLineArgs  = string.Empty;
            _workingDirectory = string.Empty;
            _coverageFile     = "coverage.xml";
            _logLevel         = NCoverLogLevel.Normal;
            _logFile          = "coverage.log";
            _copyXsl          = true;

            _assemblyFiles = new FileSet();
            _settingsFile  = string.Empty;

            _excludeAttributes = string.Empty;
            _profileIIS        = false;
            _profileService    = string.Empty;

            this.ExeName      = DefaultApplicationName;
            _programArguments = new StringBuilder();
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NCover"/> class.
        /// </summary>
        public NCover()
        {
            _commandLineExe = string.Empty;
            _commandLineArgs = string.Empty;
            _workingDirectory = string.Empty;
            _coverageFile = "coverage.xml";
            _logLevel = NCoverLogLevel.Normal;   // Since Quiet and Normal are same until Peter fixes bug.
            _logFile = "coverage.log";

            _assemblyList = string.Empty;
            _assemblyFiles = new ITaskItem[0];
            _settingsFile = string.Empty;

            _excludeAttributes = string.Empty;
            _profileIIS = false;
            _profileService = string.Empty;

            _registerProfiler = true;
            _xmlFormat = NCoverXmlFormat.Xml1;
            _profiledProcessModule = string.Empty;
        }
Exemple #3
0
        /// <summary>
        /// Build the Xml .ncoversettings file to pass to the NCover.Console executable using NCover 1.5 syntax.
        /// </summary>
        private static void _BuildTempSettingsXmlFileForNCover15(
            int versionNumber,
            string settingsFile,
            string commandLineExe,
            string commandLineArgs,
            string workingDirectory,
            string assemblyList,
            string[] assemblyFiles,
            string coverageFile,
            NCoverLogLevel logLevel,
            string logFile,
            string excludeAttributes,
            bool profileIIS,
            string profileService,
            NCoverXmlFormat xmlFormat,
            string profiledProcessModule)
        {
            using (Stream fileStream = File.Create(settingsFile))
            {
                XmlTextWriter xmlTextWriter = new XmlTextWriter(fileStream, Encoding.UTF8);
                xmlTextWriter.Indentation = 2;
                xmlTextWriter.Formatting = Formatting.Indented;

                xmlTextWriter.WriteStartDocument();
                xmlTextWriter.WriteStartElement("ProfilerSettings");
                xmlTextWriter.WriteElementString("CommandLineExe", commandLineExe);
                if (commandLineArgs != null && commandLineArgs.Length > 0)
                {
                    xmlTextWriter.WriteElementString("CommandLineArgs", commandLineArgs);
                }
                if (workingDirectory != null && workingDirectory.Length >= 0)
                {
                    xmlTextWriter.WriteElementString("WorkingDirectory", workingDirectory);
                }

                // For NCover 1.5.4 onwards we write each assembly file as a separate node.
                _WriteAssemblyNodes(assemblyList, assemblyFiles, xmlTextWriter);

                if (coverageFile != null && coverageFile.Length >= 0)
                {
                    xmlTextWriter.WriteElementString("CoverageXml", coverageFile);
                    if (versionNumber >= 157)
                    {
                        xmlTextWriter.WriteElementString("XmlFormat", xmlFormat.ToString());
                    }
                }
                if (logLevel == NCoverLogLevel.Quiet)
                {
                    if (versionNumber == 154)
                    {
                        // HACK: Setting NoLog to "true" results in NCover hanging in the NCover 1.5.4 release
                        // For now we will just leave at false and always write a log file until Peter fixes it.
                        xmlTextWriter.WriteElementString("LogFile", logFile);
                        xmlTextWriter.WriteElementString("VerboseLog", "false");
                        xmlTextWriter.WriteElementString("NoLog", "false");
                    }
                    else
                    {
                        // NCover 1.5.5 onwards has the fix.
                        xmlTextWriter.WriteElementString("LogFile", string.Empty);
                        xmlTextWriter.WriteElementString("VerboseLog", "false");
                        xmlTextWriter.WriteElementString("NoLog", "true");
                    }
                }
                else
                {
                    xmlTextWriter.WriteElementString("LogFile", logFile);
                    xmlTextWriter.WriteElementString("VerboseLog", (logLevel == NCoverLogLevel.Verbose).ToString().ToLower());
                    xmlTextWriter.WriteElementString("NoLog", "false");
                }
                if (excludeAttributes != null && excludeAttributes.Length > 0)
                {
                    string[] eachExcludeAttributes = excludeAttributes.Split(';');
                    foreach (string excludeAttribute in eachExcludeAttributes)
                    {
                        xmlTextWriter.WriteElementString("ExclusionAttributes", excludeAttribute);
                    }
                }
                if (versionNumber >= 158 && profiledProcessModule.Length > 0)
                {
                    xmlTextWriter.WriteElementString("ProfileProcessModule", profiledProcessModule);
                }
                xmlTextWriter.WriteElementString("ProfileIIS", XmlConvert.ToString(profileIIS));
                if (profileService != null && profileService.Length > 0)
                {
                    xmlTextWriter.WriteElementString("ProfileService", profileService);
                }
                xmlTextWriter.WriteElementString("DumpOnErrorNormal", "false");
                xmlTextWriter.WriteElementString("DumpOnErrorFull", "false");
                // Some NCover 1.5.5 specific features
                if (versionNumber >= 155)
                {
                    xmlTextWriter.WriteElementString("CoverageBinary", "Coverage.bcv");
                    xmlTextWriter.WriteElementString("AutoExclude", "true");
                }

                xmlTextWriter.WriteEndElement(); // ProfilerSettings
                xmlTextWriter.WriteEndDocument();
                xmlTextWriter.Flush();

                fileStream.Close();
            }
        }
Exemple #4
0
        /// <summary>
        /// Build the Xml .ncoversettings file to pass to the NCover.Console executable using NCover 1.3.3 syntax.
        /// </summary>
        private static void _BuildTempSettingsXmlFileForNCover133(
            string settingsFile,
            string commandLineExe,
            string commandLineArgs,
            string workingDirectory,
            string assemblyList,
            string[] assemblyFiles,
            string coverageFile,
            NCoverLogLevel logLevel,
            string logFile)
        {
            using (Stream fileStream = File.Create(settingsFile))
            {
                XmlTextWriter xmlTextWriter = new XmlTextWriter(fileStream, Encoding.UTF8);
                xmlTextWriter.Indentation = 2;
                xmlTextWriter.Formatting = Formatting.Indented;

                xmlTextWriter.WriteStartDocument();
                xmlTextWriter.WriteStartElement("ProfilerSettings");
                xmlTextWriter.WriteElementString("CommandLineExe", commandLineExe);
                xmlTextWriter.WriteElementString("CommandLineArgs", commandLineArgs.Replace("\"", ""));
                xmlTextWriter.WriteElementString("WorkingDirectory", workingDirectory);

                // Write assembly names as semi-colon delimited string.
                _WriteAssemblyNamesForNCover133(assemblyList, assemblyFiles, xmlTextWriter);

                xmlTextWriter.WriteElementString("CoverageFile", coverageFile);
                if (logLevel == NCoverLogLevel.Quiet)
                {
                    xmlTextWriter.WriteElementString("LogFile", string.Empty);
                    xmlTextWriter.WriteElementString("VerboseLog", "false");
                    xmlTextWriter.WriteElementString("NoLog", "true");
                }
                else
                {
                    xmlTextWriter.WriteElementString("LogFile", logFile);
                    xmlTextWriter.WriteElementString("VerboseLog", (logLevel == NCoverLogLevel.Verbose).ToString().ToLower());
                    xmlTextWriter.WriteElementString("NoLog", "false");
                }
                xmlTextWriter.WriteElementString("NoXslCopy", XmlConvert.ToString(true));

                xmlTextWriter.WriteEndElement(); // ProfilerSettings
                xmlTextWriter.WriteEndDocument();
                xmlTextWriter.Flush();

                fileStream.Close();
            }
        }
Exemple #5
0
        /// <summary>
        /// Build a command line using NCover 1.5.x syntax.
        /// </summary>
        private static string _BuildCommandLineForNCover15(
            int versionNumber,
            string commandLineExe,
            string commandLineArgs,
            string workingDirectory,
            string assemblyList,
            string coverageFile,
            NCoverLogLevel logLevel,
            string logFile,
            string excludeAttributes,
            bool profileIIS,
            string profileService,
            bool registerCoverLib,
            string commandLineFormatToken)
        {
            StringBuilder programArguments = new StringBuilder();
            if (registerCoverLib && versionNumber >= 157)
            {
                programArguments.Append(commandLineFormatToken);
                programArguments.Append("//reg");
            }
            if (workingDirectory.Length > 0)
            {
                programArguments.Append(commandLineFormatToken);
                programArguments.AppendFormat("//w \"{0}\"", workingDirectory);
            }
            if (coverageFile.Length > 0 && coverageFile != "coverage.xml")
            {
                programArguments.Append(commandLineFormatToken);
                programArguments.AppendFormat("//x \"{0}\"", coverageFile);
            }
            if (logLevel == NCoverLogLevel.Verbose)
            {
                programArguments.Append(commandLineFormatToken);
                programArguments.AppendFormat("//v");
            }
            if (logFile.Length > 0 && logFile != "coverage.log")
            {
                programArguments.Append(commandLineFormatToken);
                programArguments.AppendFormat("//l \"{0}\"", logFile);
            }
            if (assemblyList.Length > 0)
            {
                programArguments.Append(commandLineFormatToken);
                programArguments.AppendFormat("//a {0}", assemblyList);
            }
            if (excludeAttributes.Length > 0)
            {
                programArguments.Append(commandLineFormatToken);
                programArguments.AppendFormat("//ea {0}", excludeAttributes);
            }
            if (profileIIS)
            {
                programArguments.Append(commandLineFormatToken);
                programArguments.AppendFormat("//iis");
            }
            else if (profileService.Length > 0)
            {
                programArguments.Append(commandLineFormatToken);
                programArguments.AppendFormat("//svc \"{0}\"", profileService);
            }
            else
            {
                programArguments.Append(commandLineFormatToken);
                programArguments.AppendFormat("\"{0}\"", commandLineExe);
                if (commandLineArgs.Length > 0)
                {
                    programArguments.Append(commandLineFormatToken);
                    // No need to put quotes around arguments for NCover 1.5 as all are passed through.
                    programArguments.AppendFormat("{0}", commandLineArgs);
                }
            }

            return programArguments.ToString();
        }
Exemple #6
0
        /// <summary>
        /// Build a command line using NCover 1.3.3 syntax.
        /// </summary>
        private static string _BuildCommandLineForNCover133(
            string commandLineExe,
            string commandLineArgs,
            string workingDirectory,
            string assemblyList,
            string coverageFile,
            NCoverLogLevel logLevel,
            string logFile,
            string commandLineFormatToken)
        {
            StringBuilder programArguments = new StringBuilder();
            if (workingDirectory.Length > 0)
            {
                programArguments.Append(commandLineFormatToken);
                programArguments.AppendFormat("/w \"{0}\"", workingDirectory);
            }
            if (coverageFile.Length > 0 && coverageFile != "coverage.xml")
            {
                programArguments.Append(commandLineFormatToken);
                programArguments.AppendFormat("/x \"{0}\"", coverageFile);
            }
            if (logLevel == NCoverLogLevel.Verbose)
            {
                programArguments.Append(commandLineFormatToken);
                programArguments.AppendFormat("/v");
            }
            if (logFile.Length > 0 && logFile != "coverage.log")
            {
                programArguments.Append(commandLineFormatToken);
                programArguments.AppendFormat("/l \"{0}\"", logFile);
            }
            if (assemblyList.Length > 0)
            {
                programArguments.Append(commandLineFormatToken);
                programArguments.AppendFormat("/a {0}", assemblyList);
            }
            programArguments.Append(commandLineFormatToken);
            programArguments.AppendFormat("/c \"{0}\"", commandLineExe);
            if (commandLineArgs.Length > 0)
            {
                programArguments.Append(commandLineFormatToken);
                // Replace any quotes as we will add our own around the entire expression.
                programArguments.AppendFormat("\"{0}\"", commandLineArgs.Replace("\"", ""));
            }

            return programArguments.ToString();
        }
Exemple #7
0
        /// <summary>
        /// Builds the temp settings XML file for NCover.
        /// </summary>
        /// <param name="version">The version.</param>
        /// <param name="ncoverPath">The ncover path.</param>
        /// <param name="settingsFile">The settings file.</param>
        /// <param name="commandLineExe">The command line exe.</param>
        /// <param name="commandLineArgs">The command line args.</param>
        /// <param name="workingDirectory">The working directory.</param>
        /// <param name="assemblyList">The assembly list.</param>
        /// <param name="assemblyFiles">The assembly files.</param>
        /// <param name="coverageFile">The coverage file.</param>
        /// <param name="logLevel">The log level.</param>
        /// <param name="logFile">The log file.</param>
        /// <param name="excludeAttributes">The exclude attributes.</param>
        /// <param name="profileIIS">If set to <c>true</c> profile IIS.</param>
        /// <param name="profileService">The profile service.</param>
        /// <param name="xmlFormat">The XML format to write out (new feature in 1.5.7).</param>
        /// <param name="profiledProcessModule">Name of the profiled process.</param>
        /// <returns>
        /// Command line switch necessary for passing as an argument.
        /// </returns>
        internal static string BuildTempSettingsXmlFileForNCover(
            string version,
            string ncoverPath,
            string settingsFile,
            string commandLineExe,
            string commandLineArgs,
            string workingDirectory,
            string assemblyList,
            string[] assemblyFiles,
            string coverageFile,
            NCoverLogLevel logLevel,
            string logFile,
            string excludeAttributes,
            bool profileIIS,
            string profileService,
            NCoverXmlFormat xmlFormat,
            string profiledProcessModule)
        {
            if (version == null || version.Length == 0)
            {
                version = _ReadNCoverConsoleVersion(ncoverPath);
            }
            int versionNumber = int.Parse(version.Replace(".", ""));

            if (versionNumber < 150)
            {
                _BuildTempSettingsXmlFileForNCover133(
                    settingsFile, commandLineExe, commandLineArgs, workingDirectory,
                    assemblyList, assemblyFiles, coverageFile, logLevel, logFile);
                return "/r";
            }
            else
            {
                _BuildTempSettingsXmlFileForNCover15(
                    versionNumber, settingsFile, commandLineExe, commandLineArgs, workingDirectory,
                    assemblyList, assemblyFiles, coverageFile, logLevel, logFile, excludeAttributes,
                    profileIIS, profileService, xmlFormat, profiledProcessModule);
                return "//r";
            }
        }
Exemple #8
0
        /// <summary>
        /// Creates the command line arguments.
        /// </summary>
        /// <param name="version">The version.</param>
        /// <param name="ncoverPath">The ncover path.</param>
        /// <param name="commandLineExe">The command line exe.</param>
        /// <param name="commandLineArgs">The command line args.</param>
        /// <param name="workingDirectory">The working directory.</param>
        /// <param name="assemblyList">The assembly list.</param>
        /// <param name="coverageFile">The coverage file.</param>
        /// <param name="logLevel">The log level.</param>
        /// <param name="logFile">The log file.</param>
        /// <param name="excludeAttributes">The exclude attributes.</param>
        /// <param name="profileIIS">if set to <c>true</c> [profile IIS].</param>
        /// <param name="profileService">The profile service.</param>
        /// <param name="includeFormatting">if set to <c>true</c> include formatting.</param>
        /// <param name="registerCoverLib">Whether to register CoverLib.dll.</param>
        /// <param name="commandLineFormatToken">The command line format token.</param>
        /// <returns></returns>
        public static string CreateCommandLineArguments(			
            string version,
            string ncoverPath,
            string commandLineExe,
            string commandLineArgs,
            string workingDirectory,
            string assemblyList,
            string coverageFile,
            NCoverLogLevel logLevel,
            string logFile,
            string excludeAttributes,
            bool profileIIS,
            string profileService,
            bool includeFormatting,
            bool registerCoverLib,
            string commandLineFormatToken)
        {
            string commandLine;
            if (version == null || version.Length == 0)
            {
                version = _ReadNCoverConsoleVersion(ncoverPath);
            }
            int versionNumber = int.Parse(version.Replace(".", ""));

            if (versionNumber < 150)
            {
                commandLine = _BuildCommandLineForNCover133(
                    commandLineExe, commandLineArgs, workingDirectory,
                    assemblyList,  coverageFile, logLevel, logFile, commandLineFormatToken);
            }
            else
            {
                commandLine = _BuildCommandLineForNCover15(
                    versionNumber, commandLineExe, commandLineArgs, workingDirectory,
                    assemblyList, coverageFile, logLevel, logFile, excludeAttributes,
                    profileIIS, profileService, registerCoverLib, commandLineFormatToken);
            }
            if (!includeFormatting)
            {
                commandLine = commandLine.Replace(commandLineFormatToken, " ");
            }
            return commandLine;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="NCoverTask"/> class.
        /// </summary>
        public NCoverTask()
        {
            _version = "1.5";
            _commandLineExe = string.Empty;
            _commandLineArgs = string.Empty;
            _workingDirectory = string.Empty;
            _coverageFile = "coverage.xml";
            _logLevel = NCoverLogLevel.Normal;
            _logFile = "coverage.log";
            _copyXsl = true;

            _assemblyFiles = new FileSet();
            _settingsFile = string.Empty;

            _excludeAttributes = string.Empty;
            _profileIIS = false;
            _profileService = string.Empty;

            this.ExeName = DefaultApplicationName;
            _programArguments = new StringBuilder();
        }
Exemple #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NCoverTask"/> class.
        /// </summary>
        public NCoverTask()
        {
            _commandLineExe = string.Empty;
            _commandLineArgs = string.Empty;
            _workingDirectory = string.Empty;
            _coverageFile = "coverage.xml";
            _logLevel = NCoverLogLevel.Normal;
            _logFile = "coverage.log";

            _assemblyFiles = new FileSet();
            _assemblyList = string.Empty;
            _settingsFile = string.Empty;

            _excludeAttributes = string.Empty;
            _profileIIS = false;
            _profileService = string.Empty;

            _registerProfiler = true;
            _xmlFormat = NCoverXmlFormat.Xml1;
            _profiledProcessModule = string.Empty;

            this.ExeName = DefaultApplicationName;
            _programArguments = new StringBuilder();
        }