且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

创建一个Visual Studio项目编程

更新时间:2022-12-31 09:33:55

EnvDTE80,EnvDTE90和EnvDTE100是VS 8.0(2005年),9.0 DTE类型库(2008年)和10.0(2010),相应地。

EnvDTE80, EnvDTE90 and EnvDTE100 are DTE type libraries for VS 8.0 (2005), 9.0 (2008) and 10.0 (2010), correspondingly.

有只有两个DTE根对象接口,VS2010的 - DTE2是最新的。因此,要获得DTE对象为VS 2010,你做的:

There are only two DTE root object interfaces, as of VS2010 - DTE2 being the latest. So, to get the DTE object for VS 2010, you do:

System.Type type = System.Type.GetTypeFromProgID("VisualStudio.DTE.10.0");
Object obj = System.Activator.CreateInstance(type, true);
EnvDTE8.DTE2 dte = (EnvDTE100.DTE2)obj;

注意,进程id是10.0,但变量类型仍然是 EnvDTE8.DTE2

其余部分应该从那里工作。还要注意的是,你总是可以投 Solution4 Solution2 如果你需要它(但 GetProjectTemplate 应可直接在 Solution4 )。

The rest should work from there. Note also that you can always cast Solution4 to Solution2 if you need it (but GetProjectTemplate should be available directly on Solution4).