5

我需要使用Roslyn对 Web 应用程序的源代码(包括其视图)进行一些分析。

由于它只能解析 C# 文件而不能解析 razor 视图,因此我计划将视图转换为未编译的 .cs 文件,然后让 Roslyn 解析它。

我怎样才能做到这一点?

4

2 回答 2

11

我认为扩展包Razor Generator是您正在寻找的。

从 Razor 文件(.cshtml 文件)生成源代码,允许将它们编译到您的程序集中。支持 MVC、网页和独立模板。

于 2013-09-16T10:43:45.950 回答
1

I am generating .cs file from Razor .cshtml files with help of Razor Generator library.

Generated cs files contains line information from the .cshtml source files. So if you run your Roslyn analyzer against .cs files you can map the source line from .cs file back to the original .cshtml file.

于 2017-03-09T11:45:23.850 回答