Fionn
Fionn

Reputation: 11285

Is there a way to benefit from the AST of the Roslyn C# compiler directly?

I'm wondering if it is possible to access the C# AST (Abstract Syntax Tree) used by the C# Compiler during a build directly? I know I can get the AST for a given project using the Roslyn API but that would require to rereading and reparsing the source code as I understand it.

The idea is to improve a custom MSBuild task (currently using Visual Studio 2017, dotnet core) used for analyzing some properties of the resulting program.

To speed up the process, it would be great to somehow plug into the compiler or at least access cached data.

No modification of the AST is required, so this is only about read only access.

Upvotes: 3

Views: 1742

Answers (1)

Jason Malinowski
Jason Malinowski

Reputation: 19031

Yes, if you want to analyze the trees, we have a whole feature for that. Documentation is here.

Upvotes: 2

Related Questions