We are trying to use the Microsoft.Build NuGet package to be able to programatically analyse the configuration mapping in solution files.
As an example to be able to detect when a project is being built using Debug when the solution is being built using Release.
We are able to use the SolutionFile.Parse to load the solution file but it's not clear how the configuration mapping can be analysed.
Is it possible to do something like this?
I created a blank solution, added a project, and then edited the configurations in the solution and in the project to add a 'Sln' and a 'Proj' prefix, respectively. The solution has 'SlnDebug' and 'SlnRelease'. The project has 'ProjDebug' and 'ProjRelease'.
This yields the following SLN file:
The following lines map the solution's Configuration|Platform of 'SlnDebug|Any CPU' to the project's Configuration|Platform of 'ProjDebug|Any CPU'.
Using this SLN file as a test file will help to understand what
SolutionFile.Parse(string solutionFile)is doing. Also see "Solution (.sln) file" for documentation on the file format.The following code example parses a solution file and compares the solution level and project level Configuration and Platform values.
Note the special case for 'Any CPU'. For legacy reasons, solutions use 'Any CPU' (with a space) and projects use 'AnyCPU' (with no space) and this should be treated as a matching platform.
This example code is intended to illustrate how the
SolutionFileobject returned byParse()can be used and hopefully this makes the mapping clearer.