简体   繁体   中英

EnvDTE Visual Studio 2013 : get the progID?

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 ?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM