title: Getting EnvDTE.DTE instance outside Visual Studio IDE
body: <p>I am creating a project automation tool in Visual Studio 2013 where I have my own project template and I am trying to add it to an existing solution programatically.I am using the following code in a console application. </p>
  
  <pre><code>EnvDTE.DTE dte = (EnvDTE.DTE)Marshal.GetActiveObject("VisualStudio.DTE.12.0");
  string solDir = dte.Solution.FullName;
  solDir=solDir.Substring(0, solDir.LastIndexOf("\\"));
  dte.Solution.AddFromTemplate(path, solDir+"\\TestProj", "TestProj", false);
  </code></pre>
  
  <p>It is working when I run the application from Visual Studio IDE. But when I try to run the exe from command prompt, I get the following exception.</p>
  
  <pre><code>Unhandled Exception: System.Runtime.InteropServices.COMException: Operation unav
  ailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))
  at System.Runtime.InteropServices.Marshal.GetActiveObject(Guid&amp; rclsid, IntPtr reserved, Object&amp;   ppunk)
  at System.Runtime.InteropServices.Marshal.GetActiveObject(String progID)
  at ProjectAutomation.Console.Program.Main(String[] args) 
  </code></pre>
  
  <p>I want to know whether there is any way to get the active EnvDTE.DTE instance outside Visual Studio IDE .?</p>