heltonbiker
heltonbiker

Reputation: 27615

Can I analyze Project (.csproj) and Solution (.sln) relationships with Roslyn?

I have just started to use Roslyn, because I would like to develop some static analysis pet projects focused on generating dependency graphs (the output would be .dot files to be compiled to .pdf with Graphviz).

I can see the potential to analyze the code in a per-file basis, but I need the following operations (more or less):

  1. Given a solution.sln file, find all project.csproj files referenced by it;
  2. Given a project.csproj file, find all sourcecode.cs files referenced by it;
  3. Parse these files with Roslyn, as usual;
  4. Have a solutionwide parse tree or something, where namespaces spanning more than one project would have its classes grouped together.

Specifically, my question is: can I perform operations 1, 2 and 4 with Roslyn, or should I use other tools / techniques instead? Any suggestion?

P.S. I see there is a VisualStudioWorkspace but I couldn't figure out what I have to do to use it, yet.

Upvotes: 2

Views: 1206

Answers (1)

SLaks
SLaks

Reputation: 888047

Yes; this is certainly possible.

VisualStudioWorkspace is used within VS itself; you should only use that from within a VS addin to access the current solution.

To load a solution yourself, use MSBuildWorkspace. You will then want to merge symbols from the Compilations for each project.

Upvotes: 6

Related Questions