I'm trying to build a simple program to static code analysis with provided package from Microsoft. So I wan to open solution then open projects via code then get all the document and analyze with my methods.
This is my method, I'm calling somewhere else, and I double checked solution path is correct. You can see my namespaces that I used.
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.MSBuild;
public class Fixer
{
public Fixer(string solutionPath)
{
using (var workspace = MSBuildWorkspace.Create())
{
_solution = workspace.OpenSolutionAsync(_solutionPath).Result;
}
}
}
After that I want to
public IEnumerable<Document> GetDocuments(Solution solution)
{
foreach (var projectId in solution.ProjectIds)
{
var project = solution.GetProject(projectId);
foreach (Document document in project.Documents)
{
if (document.SupportsSyntaxTree)
yield return document;
}
}
}
public IEnumerable<MethodDeclarationSyntax> GetMethods(IEnumerable<Document> documents)
{
return documents.SelectMany(p => p.GetSyntaxRootAsync().Result.DescendantNodes().OfType<MethodDeclarationSyntax>());
}
Main problem is its not open solution at all. When I checked workspace object. There is diagnostic property and says
{[Failure] Cannot open project '.\RunningDiagnostics.csproj' because the language 'C#' is not supported.}
For all project in that solution.
I tried to update nuget packages that I used. Nothing happened. What is the main problem ? And guidance will be appreciated.
Thank you.