简体   繁体   中英

How to use Roslyn Code Analysis API with MVC 6 projects

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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