/// <summary> /// To check solution with StyleCop. /// </summary> /// <param name="options"></param> private static void CheckWithStyleCop(Options options) { Debug.WriteLine("To check with StyleCop"); //var exePath = @"f:\_E_\jb-cl\StyleCop.exe"; //var output = @"..\Reports\InspectCode_Report.xml"; //var cachesHome = @"..\Reports\InspectCode_Cache\"; //var slns = Directory.GetFiles(options.RepositoryPath, "*.sln", SearchOption.AllDirectories); //var uri = new Uri(options.RepositoryPath); //Debug.Indent(); //foreach (var sln in slns) //{ // var uri1 = new Uri(sln); // var uri2 = uri.MakeRelativeUri(uri1); // var cmdLine = string.Format(@"""{0}""", // uri2.ToString()); // Debug.WriteLine(exePath + " " + cmdLine); //} //Debug.Unindent(); }
/// <summary> /// Program entry point. /// </summary> /// <example> /// -r "f:\_E_\SolutionTool" -t default.xml -b "./output/$(Configuration)/" -i "f:\_E_\jb-cl\inspectcode.exe" -l slntool.log /// </example> /// <param name="args"></param> static void Main(string[] args) { Debug.Listeners.Add(new ConsoleTraceListener()); var options = new Options(); var parser = new Parser(); if (!Parser.Default.ParseArguments(args, options)) { return; } Console.WriteLine("Begin checking " + options.Repository); var pathOfRepository = Path.GetFullPath(options.Repository); var pathOfTemplate = Path.GetFullPath(options.Template); if (!Directory.Exists(pathOfRepository)) { Console.WriteLine("Repository directory does not exist: [" + options.Repository + "]"); } if (!File.Exists(pathOfTemplate)) { Console.WriteLine("Template File does not exist: [" + options.Repository + "]"); } else { var di = new DirectoryInfo(pathOfRepository); var fi = new DirectoryInfo(pathOfTemplate); var project = new Project { Name = di.Name, Path = pathOfRepository, CreateTime = DateTime.Now, }; var ruleSet = new RuleSet { new FileStructureRule { Name = "File Structure Rule", IsEnabled = true, Template = fi.Name, }, new OutputPathRule { Name = "Output Path Rule", IsEnabled = true, Path = options.OutputBuildPath, }, }; if (!string.IsNullOrWhiteSpace(options.InspectCodeExePath)) { ruleSet.Add(new CodeAnalysisRule { Name = "Code Analysis Rule", IsEnabled = true, Path = options.InspectCodeExePath, }); } var ruleRunner = new RuleRunner(); project.RuleSet = ruleSet; ruleRunner.RunProject(project, (report,log) => { if (report != null) { Console.WriteLine(report.GetText()); } if (!string.IsNullOrWhiteSpace(options.LogFile)) { var logFile = Path.GetFullPath(options.LogFile); using (var sw = File.AppendText(logFile)) { sw.Write(report.GetText()); } } }); } Console.WriteLine("Checking is done. "); Console.ReadKey(); }