Just in case someone finds this thread and needs the RunTime equivalents, see below. Note that I get an error when trying to use Marshall.GetActiveObject with a generic ProgID.
VB
' Adapted from:
' HOWTO: Automating Visual Studio .NET from outside the IDE
' http://www.mztools.com/articles/2005/MZ005.htm
Imports EnvDTE
Imports System.Runtime.InteropServices
Private Const m_VISUAL_STUDIO_2002_PROG_ID As String = "VisualStudio.DTE.7"
Private Const m_VISUAL_STUDIO_2003_PROG_ID As String = "VisualStudio.DTE.7.1"
Private Const m_VISUAL_STUDIO_2005_PROG_ID As String = "VisualStudio.DTE.8.0"
Private Const m_VISUAL_STUDIO_GENERIC_PROG_ID As String = "VisualStudio.DTE"
' Code throws an error if generic prog id is used here.
Dim visualStudioIDE1 As EnvDTE.DTE = _
Marshal.GetActiveObject(m_VISUAL_STUDIO_GENERIC_PROG_ID)
' Create an instance of the latest Visual Studio .NET IDE.
' Using a type and activator allows any version to be created.
Dim type As System.Type = _
System.Type.GetTypeFromProgID(m_VISUAL_STUDIO_GENERIC_PROG_ID)
Dim visualStudioIDE2 = _
DirectCast(System.Activator.CreateInstance(type), EnvDTE.DTE)
C#
using EnvDTE;
using System.Runtime.InteropServices;
// Adapted from:
// HOWTO: Automating Visual Studio .NET from outside the IDE
// http://www.mztools.com/articles/2005/MZ005.htm
private const string m_VISUAL_STUDIO_2002_PROG_ID = "VisualStudio.DTE.7";
private const string m_VISUAL_STUDIO_2003_PROG_ID = "VisualStudio.DTE.7.1";
private const string m_VISUAL_STUDIO_2005_PROG_ID = "VisualStudio.DTE.8.0";
private const string m_VISUAL_STUDIO_GENERIC_PROG_ID = "VisualStudio.DTE";
// Code throws an error if generic prog id is used here.
EnvDTE.DTE visualStudioIDE1 =
Marshal.GetActiveObject(m_VISUAL_STUDIO_GENERIC_PROG_ID);
// Create an instance of the latest Visual Studio .NET IDE.
// Using a type and activator allows any version to be created.
System.Type type =
System.Type.GetTypeFromProgID(m_VISUAL_STUDIO_GENERIC_PROG_ID);
object visualStudioIDE2 =
((EnvDTE.DTE)(System.Activator.CreateInstance(type)));