0

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);
Gifty
  • 185
  • 1
  • 2
  • 16
  • No, you didn't. `Workspaces` really cannot open the web site without `.proj` file. Check [the answer](https://stackoverflow.com/questions/25070323/roslyn-workspace-opensolutionasync-projects-always-empty) from @Jason Malinowski – George Alexandria Oct 10 '18 at 17:59
  • @GeorgeAlexandria Thank you for your response. So Is there no other way I can access my website project without .proj file? – Gifty Oct 12 '18 at 05:17
  • What do you mean under "access website"? If you want to access the code from a some file in website you can create compilation and project for it by hand. – George Alexandria Oct 12 '18 at 07:07
  • I mean I am trying to find a Property declaration and its references. The property is declared in class library project and has some references in a class under website project (update the code to find property references in question). As workspace cannot open the website proj, I couldn't get the property references in website project. – Gifty Oct 12 '18 at 07:21
  • You should create a compilation[s] from the website's source and add to it[them] reference on to your class library. When you do that you can append these compilation[s] to your solution creating a new project[s] – George Alexandria Oct 12 '18 at 16:30

0 Answers0