简体   繁体   English

有没有办法直接从 Roslyn C# 编译器的 AST 中受益?

[英]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?我想知道是否可以直接访问 C# 编译器在构建过程中使用的 C# AST(抽象语法树)? 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.我知道我可以使用 Roslyn API 获取给定项目的 AST,但这需要根据我的理解重新阅读和重新解析源代码。

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.这个想法是改进一个自定义的 MSBuild 任务(目前使用 Visual Studio 2017,dotnet 核心),用于分析结果程序的一些属性。

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.不需要修改 AST,所以这只是只读访问。

Yes, if you want to analyze the trees, we have a whole feature for that.是的,如果你想分析树木,我们有一个完整的功能。 Documentation is here . 文档在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM