从控制台应用程序运行envdte项目时出错

时间:2013-06-11 02:38:16

标签: c# visual-studio-2010 console-application envdte extensibility

我正在尝试使用我在控制台的加载项中创建的代码。

我收到错误:

Error in solution file: C:\x\x.sln
System.Runtime.InteropServices.COMException (0x80010001): Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))
   at EnvDTE.Project.get_Kind()
   at p.Program.Projects(DTE2 dte) in C:\z\p\Program.cs:line 764
   at ..
   at p.Program.Main(String[] args) in C:\z\p\Program.cs:line 60

代码:

using EnvDTE;
using EnvDTE80;
...
class Program
{
  [STAThread]
  static void Main(string[] args)
  {  
    EnvDTE80.DTE2 dte;
    object obj = null;
    System.Type t = null;
    t = System.Type.GetTypeFromProgID("VisualStudio.DTE.10.0", true);
    obj = System.Activator.CreateInstance(t, true);
    dte = (EnvDTE80.DTE2)obj;
    string[] solutionFile = ...
    dte.Solution.Open(solutionFile);
    EnvDTE.Solution solution = (EnvDTE.Solution)dte.Solution;
    IList<Project> projects = Projects((DTE2)dte);
          ...    
  }
private static IList<Project> Projects(DTE2 dte)
    {
      Projects projects = dte.Solution.Projects;
      List<Project> list = new List<Project>();
      var item = projects.GetEnumerator();
      while (item.MoveNext())
      {
         var project = item.Current as Project;
         if (project == null)
         {
            continue;
         }
         if (string.Compare(EnvDTE.Constants.vsProjectKindUnmodeled, project.Kind, System.StringComparison.OrdinalIgnoreCase) == 0)  // this is line 764
         {
             throw some_exception;
         }
         if (project.Kind == ProjectKinds.vsProjectKindSolutionFolder)
         {
             ...
         }
      }
    }
  }

最初,Intellisense告诉我

Interop type 'DTE2.ProjectKinds' cannot be embedded. Use the applicable interface instead.

我找到了一个引用告诉我,我可以转到我的参考属性,并将Embed Interop Assembly设置为False

这让我可以毫无错误地构建....但是执行会给我上面的错误。

请帮忙 - 我该如何解决这个问题?

VS2010 ......它适用于加载项......

1 个答案:

答案 0 :(得分:2)

上面的评论是我的问题的答案 -

我最终使用以下参考: http://msdn.microsoft.com/en-us/library/ms228772(v=vs.100).aspx