Getting a SemanticModel of a cshtml file?
问题 I'd like to use Roslyn to analyze semantic information within the context of a block of C# code inside a Razor View. Is there any way (within Visual Studio 2015, or even in a unit test) to get the SemanticModel that represents this code? 回答1: Razor files contain a C# projection buffer with the generated C# code (including the parts that you don't write yourself). This buffer has full Roslyn services and is exactly what you're looking for. You need to walk through the TextView's BufferGraph