在用户打开多个IDE的时候可用以下方法获取当前项目的路径:

/// <summary>
  ///
Get the project root absolute path
  /// </summary>
  /// <returns></returns>
  public string GetProjectPath()
  {
   //Moniker string definition: "!VisualStudio.DTE.7.1:"
   string strMoniker = "!VisualStudio.DTE.7.1:"
                            + System.Diagnostics.Process.GetCurrentProcess().Id.ToString();
   EnvDTE._DTE dte =(EnvDTE._DTE)this.getMSDEVFromGIT(strMoniker);

   EnvDTE.DTE devenv = dte.Solution.DTE;
    //EnvDTE.DTE devenv = 
    //                    (EnvDTE.DTE)System.Runtime.InteropServices
.Marshal.GetActiveObject(
    //                                                "VisualStudio.DTE.7.1");

   string projectFile = devenv.ActiveDocument.ProjectItem.ContainingProject.FileName;
   System.IO.FileInfo info = new System.IO.FileInfo(projectFile);

   return info.Directory.FullName;
  }

  [System.Runtime.InteropServices.DllImport("ole32.dll")] 
  public static extern int GetRunningObjectTable(int reserved, 
            out System.Runtime.InteropServices.UCOMIRunningObjectTable prot);

  [System.Runtime.InteropServices.DllImport("ole32.dll")] 
  public static extern int  CreateBindCtx(int reserved,
                    out System.Runtime.InteropServices.UCOMIBindCtx ppbc);

  private object getMSDEVFromGIT(string strProgID) 
  {  
   System.Runtime.InteropServices.UCOMIRunningObjectTable prot;  
   System.Runtime.InteropServices.UCOMIEnumMoniker pMonkEnum;  

   GetRunningObjectTable(0,out prot);   
   prot.EnumRunning(out pMonkEnum);   
   pMonkEnum.Reset();
   int fetched;   
   System.Runtime.InteropServices.UCOMIMoniker []pmon =
                
new System.Runtime.InteropServices.UCOMIMoniker[1];

   while(pMonkEnum.Next(1, pmon, out fetched) == 0)    
   {    
    System.Runtime.InteropServices.UCOMIBindCtx pCtx;    
    CreateBindCtx(0, out pCtx);    
    string str;    
    pmon[0].GetDisplayName(pCtx,null,out str);   
    if(str == strProgID)  
    { 
     object objReturnObject; 
     prot.GetObject(pmon[0],out objReturnObject);
     object ide = (object)objReturnObject; 
     return ide; 
    } 
   }
   return null;
  }