private async Task LoadSolutionImpl(string excludeFiles) { // Print message for WorkspaceFailed event to help diagnosing project load failures. _workspace.WorkspaceFailed += WriteErrorMessage; var solutionPath = _solution; _logger.Info($"Loading solution '{solutionPath}'"); // Attach progress reporter so we print projects as they are loaded. //var solution = await workspace.OpenSolutionAsync(solutionPath, new ConsoleProgressReporter()); ParsedSolution = await _workspace.OpenSolutionAsync(solutionPath); _logger.Info($"Finished loading solution '{solutionPath}'"); // TODO: Do analysis on the projects in the loaded solution _logger.Info("Extracting ouputFiles"); if (string.IsNullOrWhiteSpace(excludeFiles)) { OutputFiles = ParsedSolution.Projects .Select(p => p.OutputFilePath).ToList(); } else { OutputFiles = ParsedSolution.Projects .Where(p => !(p.OutputFilePath.Contains(excludeFiles))) .Select(p => p.OutputFilePath).ToList(); } _workspace.WorkspaceFailed -= WriteErrorMessage; }
public async Task LoadSolution(string excludeFiles) { var msBuildPath = _msBuildPath; if (!(msBuildPath.EndsWith("MSBuild.dll", StringComparison.InvariantCultureIgnoreCase))) { msBuildPath = Path.Combine(msBuildPath, "MSBuild.dll"); } _logger.Info("Using MSBuild at " + msBuildPath); Environment.SetEnvironmentVariable("MSBUILD_EXE_PATH", msBuildPath); _workspace = MSBuildWorkspace.Create(); await LoadSolutionImpl(excludeFiles); }
private static async Task ArgumentExtraction(IEnumerable <ISymbol> declaredSymbols, Solution solution, ProgramOptions options) { var argumentExtractor = new InvocationArgumentExtractor(_logger); foreach (var symbol in declaredSymbols) { var argumentResults = await argumentExtractor.FindArguments(symbol, solution); _logger.Info("Reporting location and arguments for calls to " + symbol.ToDisplayString()); foreach (var result in argumentResults.OrderBy(r => r.FilePath)) { PrintResult(result); } } }
public async Task LoadProject(string project) { var testProject = _solution.Projects.Where(p => p.Name == project).FirstOrDefault(); _logger.Info("Loaded " + testProject.Name); await AnalyzeProject(testProject, _outputFiles); }
public async Task <Solution> LoadSolution(string pathToSln) { // Print message for WorkspaceFailed event to help diagnosing project load failures. _workspace.WorkspaceFailed += (o, e) => Console.WriteLine(e.Diagnostic.Message); var solutionPath = pathToSln; _logger.Info($"Loading solution '{solutionPath}'"); // Attach progress reporter so we print projects as they are loaded. var solution = await _workspace.OpenSolutionAsync(solutionPath, new ConsoleProgressReporter(_logger)); _logger.Info($"Finished loading solution '{solutionPath}'"); return(solution); }
/// <summary> /// When multiple VisualStudio instances are found it uses the supplied logger to print information about found instances. Then waits for console input to select one. /// </summary> /// <param name="visualStudioInstances"></param> /// <returns></returns> public VisualStudioInstance SelectVisualStudioInstance(VisualStudioInstance[] visualStudioInstances) { if (visualStudioInstances.Length == 1) { return(visualStudioInstances[0]); } _logger.Warning("Multiple installs of MSBuild detected please select one:"); for (int i = 0; i < visualStudioInstances.Length; i++) { _logger.Warning($"Instance {i + 1}"); _logger.Warning($" Name: {visualStudioInstances[i].Name}"); _logger.Warning($" Version: {visualStudioInstances[i].Version}"); _logger.Warning($" MSBuild Path: {visualStudioInstances[i].MSBuildPath}"); } while (true) { var userResponse = Console.ReadLine(); if (int.TryParse(userResponse, out int instanceNumber) && instanceNumber > 0 && instanceNumber <= visualStudioInstances.Length) { return(visualStudioInstances[instanceNumber - 1]); } _logger.Info("Input not accepted, try again."); } }
private async Task SearchImplementation(IMethodSymbol call) { ITypeSymbol interfaceInfo = call.ReceiverType; try { await Task.Run(() => RunSearchInBackground(interfaceInfo)); } catch (Exception ex) { _logger.Info(ex.ToString()); } }
private static async Task RunAnalysis(ProgramOptions options) { _logger = new ConsoleLogger(verbose: options.VerboseLogging, debug: options.DebugLogging); using (var solLoader = new SolutionLoader(_logger)) { var solution = await solLoader.LoadSolution(options.PathToSolution); var extractor = new SymbolExtractorWithCompilation(_logger); var declaredSymbols = await extractor.FindSymbols(solution, options.FullTypeName, options.MethodName, options.MethodArguments); _logger.Info($"Did not find anything for {options.FullTypeName}.{options.MethodName}({string.Join(", ", options.MethodArguments)})"); await ArgumentExtraction(declaredSymbols, solution, options); } }
/// <summary> /// Searches for the latest dotNetCore SDK and extracts the MSBuild.dll path.<br/> /// After registering it a environment variable "MSBUILD_EXE_PATH" a MSBuildWorkspace is created.<br/> /// If no hintPath was supplied at construction the default directories will be searched. /// </summary> /// <returns></returns> public MSBuildWorkspace CreateWorkspace() { var msBuildPath = _locator.LocateMsBuild(_hintPath); if (!(msBuildPath.EndsWith("MSBuild.dll", StringComparison.InvariantCultureIgnoreCase))) { msBuildPath = Path.Combine(msBuildPath, "MSBuild.dll"); } _logger?.Info("Using MSBuild at " + msBuildPath); Environment.SetEnvironmentVariable("MSBUILD_EXE_PATH", msBuildPath); return(MSBuildWorkspace.Create()); }
/// <summary> /// Creates a MSBuld workspace using the MSBuild found by Microsoft.Build.Locator.MSBuildLocator. /// </summary> /// <returns></returns> /// <exception cref="VisualStudioNotFoundException">No installed VisualStudio or MSBuildTools were found.</exception> public MSBuildWorkspace CreateWorkspace() { var instance = GetVsInstance(); _logger.Info($"Using MSBuild at '{instance.MSBuildPath}' to load projects."); // NOTE: Be sure to register an instance with the MSBuildLocator // before calling MSBuildWorkspace.Create() // otherwise, MSBuildWorkspace won't MEF compose. if (!Microsoft.Build.Locator.MSBuildLocator.IsRegistered) { Microsoft.Build.Locator.MSBuildLocator.RegisterInstance(instance); } return(MSBuildWorkspace.Create()); }
public SolutionLoader(IDoLog logger, int?defaultVSInstance = null) { _logger = logger ?? new NullLogger(); // Attempt to set the version of MSBuild. var visualStudioInstances = MSBuildLocator.QueryVisualStudioInstances().ToArray(); var instance = GetInstance(visualStudioInstances, defaultVSInstance); _logger.Info($"Using MSBuild at '{instance.MSBuildPath}' to load projects."); // NOTE: Be sure to register an instance with the MSBuildLocator // before calling MSBuildWorkspace.Create() // otherwise, MSBuildWorkspace won't MEF compose. if (!MSBuildLocator.IsRegistered) { MSBuildLocator.RegisterInstance(instance); } _workspace = MSBuildWorkspace.Create(); }