public void LoadProjectSymbols() { SymbolProvider.ProjectSymbols.Clear(); var compilation = Microsoft.CodeAnalysis.CSharp.CSharpCompilation.Create(this.CurrentSolution.ToString()); foreach (var project in this.CurrentSolution.Projects) { compilation = compilation.AddReferences(project.MetadataReferences); var instance = ProjectInstances.FirstOrDefault(x => x.FullPath.Equals(project.FilePath)); if (instance.Properties.FirstOrDefault(x => x.Name.Equals("TargetPath", StringComparison.OrdinalIgnoreCase)) is Microsoft.Build.Execution.ProjectPropertyInstance prop && File.Exists(prop.EvaluatedValue)) { compilation = compilation.AddReferences(MetadataReference.CreateFromFile(prop.EvaluatedValue)); } var projectSymbols = new ProjectSymbolCache(project.Name); foreach (var refMeta in compilation.References) { var visitor = new GetAllSymbolsVisitor(); var assemblySymbol = (IAssemblySymbol)compilation.GetAssemblyOrModuleSymbol(refMeta); visitor.Visit(assemblySymbol.GlobalNamespace); projectSymbols.AssemblySymbols.Add(new AssemblySymbolCache(assemblySymbol, visitor.NamedTypes)); } SymbolProvider.ProjectSymbols.Add(projectSymbols); } }
public Microsoft.Build.Execution.ProjectInstance GetProjectInstance(string fullPath) { return(ProjectInstances.FirstOrDefault(x => x.FullPath.Equals(fullPath, StringComparison.OrdinalIgnoreCase))); }