I would like to open into memory an existing .sln file.
Example of a non-working method:
private Solution2 OpenSolution(string filePath)
{
Solution2 sln;
sln.Open(filePath);
return sln;
}
If I have an instance of Solution2 then i can call the method Open; but how can i get an instance of Solution2?
My goal is then to get the adequate project and read some of its settings… but that’s easy having access to the solution.
You can programmatically create a hidden instance of Visual Studio, and then use it to manipulate your solution. This example will list out all the projects that live in the given solution.
(The nonsense with STAThread and MessageFilter is “due to threading contention issues between external multi-threaded applications and Visual Studio”, whatever that means. Pasting in the code from http://msdn.microsoft.com/en-us/library/ms228772.aspx makes it work.)