/// <summary> /// Creates a new instance of the <see cref="SolutionReader"/> class. /// </summary> /// <param name="pathToSln">The path to the DocumentationAnalayzers solution.</param> /// <param name="analyzerProjectName">The project name of the analyzer project.</param> /// <param name="codeFixProjectName">The project name of the code fix project.</param> /// <returns>A <see cref="Task{TResult}"/> representing the asynchronous operation.</returns> public static async Task <SolutionReader> CreateAsync(string pathToSln, string analyzerProjectName = "BannedApiAnalyzer.CSharp", string codeFixProjectName = "BannedApiAnalyzer.CodeFixes") { SolutionReader reader = new SolutionReader(); reader.SlnPath = pathToSln; reader.AnalyzerProjectName = analyzerProjectName; reader.CodeFixProjectName = codeFixProjectName; reader._workspace = MSBuildWorkspace.Create(); await reader.InitializeAsync().ConfigureAwait(false); return(reader); }
/// <summary> /// The starting point of this application. /// </summary> /// <param name="args">The command line parameters.</param> /// <returns>Zero if the tool completes successfully; otherwise, a non-zero error code.</returns> internal static int Main(string[] args) { if (args.Length < 1) { Console.WriteLine("Path to sln file required."); return(1); } if (!File.Exists(args[0])) { Console.WriteLine($"Could not find solution file: {Path.GetFullPath(args[0])}"); return(1); } MSBuildLocator.RegisterDefaults(); SolutionReader reader = SolutionReader.CreateAsync(args[0]).Result; var diagnostics = reader.GetDiagnosticsAsync().Result; diagnostics = diagnostics.Sort((a, b) => a.Id.CompareTo(b.Id)); Commit commit; string commitId; using (Repository repository = new Repository(Path.GetDirectoryName(args[0]))) { commitId = repository.Head.Tip.Sha; commit = repository.Head.Tip; var output = new { diagnostics, git = new { commit.Sha, commit.Message, commit.Author, commit.Committer, Parents = commit.Parents.Select(x => x.Sha), }, }; Console.WriteLine(JsonConvert.SerializeObject(output, Formatting.Indented)); } return(0); }