EnvDTE Visual Studio 2013 : get the progID?

2.7k views Asked by At

I am trying to create a Visual Studio instance using :

EnvDTE80.DTE2 dte2;
dte2 = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.12.0");

And I am always having the exception "Invalid Class String" so I assume that the problem is "VisualStudio.DTE.12.0". But I am working on Visual Studio 2013 12.0.30501, I also tried to put only "VisualStudio.DTE" to get the most recent version, and same exception.

Also, I tried the other way :

Type t = Type.GetTypeFromProgID("VisualStudio.DTE.12.0", true);
dte2 = (EnvDTE80.DTE2)System.Activator.CreateInstance(t, true);

The problem is still there, I am running a bit out of idea... Is it really an invalid string error ?

1

There are 1 answers

0
MarmotJam On

If you are using Visual Studio 2013 Express this works to fix it:

Type t = Type.GetTypeFromProgID("WDExpress.DTE.12.0", true);
var x = (EnvDTE80.DTE2)System.Activator.CreateInstance(t, true);