I am using Roslyn to read the referenced projects of a solution like this:
MSBuildWorkspace workspace = MSBuildWorkspace.Create();
workspace.LoadMetadataForReferencedProjects = true;
Solution solution = workspace.OpenSolutionAsync(Solution).Result;
foreach (var p in solution.Projects) {
//do something with the project
}
The problem is that the solution variable does not contain projects where the files are not available locally. Meaning the project could not be loaded because the files are missing.
Is there a way to get all project references including the references where the project files are missing?
There is a way to load all projects configured int the sln file. However, it is not through roslyn.
Microsoft Build exposes Microsoft.Build.Construction.SolutionFile
.
You can get projects serveral ways, such as:
SolutionFile solutionInfo = SolutionFile.Parse(@"/path-to-sln.sln");
IEnumerable<ProjectInSolution> projectList = solutionInfo.ProjectsInOrder;
From here you could use workspace.OpenProjectAsync(project.AbsolutePath)
to load available projects. (Note, workspace is a MSBuildWorkspace
and project is a ProjectInSolution
).
This is actually what roslyn is doing under the hood through MSBuildProjectLoader. However, it only supports two behaviors for handling missing projects: log or throw exception. If you would rather throw an exception for missing projects, set workspace.SkipUnrecognizedProjects = false;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With