I have a solution named RoslynTesting.sln has 2 projects (class library and a website)
var msWorkspace = MSBuildWorkspace.Create();
var solution = await msWorkspace.OpenSolutionAsync(@"E:\RoslynTesting\RoslynTesting.sln");
msWorkspace.OpenSolutionAsync()
gets only the class library project and not the website project.
I could see a message in msWorkspace.Diagnostics
like "[Failure] Project file not found: 'E:\RoslynTesting\WebSite1\'"
Am I missing something or Microsoft.CodeAnalysis.CSharp.Workspaces.dll doesn't support Website projects?
Code to find property declaration and references:
var msWorkspace = MSBuildWorkspace.Create()
var solution = await msWorkspace.OpenSolutionAsync(@"E:\RoslynTesting\RoslynTesting.sln");
var documents = solution.Projects.SelectMany(x => x.Documents).ToList();
var classFile = documents.Where(x => x.FilePath == filePath).FirstOrDefault();
var invocation = await classFile.GetSyntaxRootAsync();
var classNode = invocation.DescendantNodes().OfType<ClassDeclarationSyntax>().Where(x => x.Identifier.Text == className).FirstOrDefault();
var propertyDeclarationNode = classNode.DescendantNodes().OfType<PropertyDeclarationSyntax>().Where(x => x.Identifier.Text == propertyName).FirstOrDefault();
var model = await classFile.GetSemanticModelAsync();
ISymbol methodSymbol = model.GetDeclaredSymbol(propertyDeclarationNode);
var propertyReferences = await SymbolFinder.FindReferencesAsync(methodSymbol, solution);