How to use Roslyn Code Analysis API with MVC 6 projects

流过昼夜 提交于 2019-12-11 10:55:12

问题


I intend to use the new Roslyn Code Analysis API with an MVC 6 project.

However, when I run this code:

string pathToSolution = @"..\..\..\WebApplicationComplex.sln";
const string projectName = "RoslynWebAPIProject";
MSBuildWorkspace workspace = MSBuildWorkspace.Create();
Solution solutionToAnalyze = workspace.OpenSolutionAsync(pathToSolution).Result;
Project sampleProjectToAnalyze = solutionToAnalyze.Projects.Where((proj) => proj.Name == projectName).FirstOrDefault();
Compilation sampleToAnalyzeCompilation = sampleProjectToAnalyze.GetCompilationAsync().Result;

I only get the analyzer project and nothing of the MVC 6 project, so the sampleProjectToAnalyze remains null.

How should I analyze that type of projects?


回答1:


You need to use the DNX Workspace.
Add a reference to that package, then create a new ProjectJsonWorkspace(jsonPath)



来源:https://stackoverflow.com/questions/32697047/how-to-use-roslyn-code-analysis-api-with-mvc-6-projects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!