views:

155

answers:

2

I'm trying to get a list of all projects within a specified VS2008 solution. (this is a stand-alone console app, it is not a Visual Studio add-in)

My code works with VS2005 solutions, but I get all sorts of ugly COM errors trying to use the VS2008 object.

What I mean is: This:

Type _visualStudioType = Type.GetTypeFromProgID("VisualStudio.DTE.8.0");  
DTE _dte = Activator.CreateInstance(_visualStudioType) as DTE;  

works and this:

Type _visualStudioType = Type.GetTypeFromProgID("VisualStudio.DTE.9.0");  
DTE _dte = Activator.CreateInstance(_visualStudioType) as DTE;  

doesn't (currently throws COM error 8001010a)

I have both relevant classes registered in the registry, and all appropriate assemblies are referenced.


Edit: I'll go with basic parsing of the .sln file, even if I have to do a bit of rewriting, as text manipulation is bound to work without all the nasty interop stuff. However, I can't seem to find a description of the .sln format, any resources?

+1  A: 

You may want to look at this: Library for parsing Visual Studio Solution files? If parsing the .sln directly turns out to be your only option.

As to your current problem, some other people have had your issue. The KB246018 says check out your antivirus as the leading cause (example is word, but same applies to VS). Try excluding the VS directory entirely.

Nick Craver
does not work with the antivirus turned off, tooAnd if I try DTE2 _dte = (DTE2) Microsoft.VisualBasic.Interaction.CreateObject("VisualStudio.DTE.9.0", ""); I get a "Cannot create ActiveX component." error.
SWeko
+1  A: 

You are getting an RPC error: "server is busy". That might be because Visual Studio is actually busy, debugging your console mode program. Short from debugging with Console.WriteLine() statements, try another debugger. The Windows SDK has the clrdbg.exe and mdbg.exe debuggers. The .NET 2.0 SDK had a GUI debugger iirc.

Hans Passant
Nope, fails even when not debugging... And, yes, I kinda try to lift myself by pulling on my shoestrings.
SWeko
I had no problem running the same code. I can't think of a reason why you would, other than adding the wrong reference. I did use envdte.dll from the VS2008 install directory.
Hans Passant