问题
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