The initial problem is that I have a huge solution where projects have different options (e.g., x64 or x86 configuration, allow unsafe code or not and so on). I'm trying to use Roslyn (2.9.0) to compile\parse that solution with DEBUG x64 configuration. Compilation of some projects has failed because 'DEBUG x86' should be used only.
I create a test solution with 'DEBUG x64' configuration.
Project A is a console application (DEBUG x64).
Project B is a library (DEBUG x86)
and writing this code:
MSBuildLocator.RegisterDefaults();
_workspace = MSBuildWorkspace.Create(props);
_workspace.SkipUnrecognizedProjects = false;
_solution = _workspace.OpenSolutionAsync(solutionFilePath).Result;
var projectsGpaph = _solution.GetProjectDependencyGraph();
var projects = projectsGpaph.GetTopologicallySortedProjects();
When "props" is not set
_workspace.Diagnostics is Empty and "projects" have a right order (library, then app)
B: project.CompilationOptions.Platform is AnyCpu
A: project.CompilationOptions.Platform is AnyCpu32BitPreferred
When "props" is set to
var props = new Dictionary<string, string>()
{
{"Configuration", "Debug"},
{"Platform", "x64"}
};
_workspace.Diagnostics is Empty, "projects" have a wrong order:
A: project.CompilationOptions.Platform is X64
B: project.CompilationOptions.Platform is X64
and an exception has thrown when I execute "project.GetCompilationAsync().Result":
System.ArgumentException: 'Reference of type
'Microsoft.CodeAnalysis.UnresolvedMetadataReference' is not valid for this
compilation.
Parameter name: references[0]'
How to force Roslyn to take into account .sln\.csproj settings?