无法投DTE,项目或解决方案VCProject和VCCodeModel [英] Unable to cast DTE, project or solution to VCProject and VCCodeModel

查看:384
本文介绍了无法投DTE,项目或解决方案VCProject和VCCodeModel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得关于C + =程序的一些信息,通过代码。我有一些成功的EnvDTE,现在我需要用VCProject和VCCodeModel和我遇到的问题铸件(希望这是所有...)

I am trying to get some information about c+= programs, through code. I have had some success with EnvDTE, now I need to use VCProject and VCCodeModel and I am running into casting problems (hope that is all...)

在工作一流的,我有一个DTE 应用程序从连接通过

In the working class, I have a DTE "application" passed from the Connect.

我有:

EnvDTE.Project project = application.SelectedItems.Item(1).Project;
EnvDTE.Solution sol = (EnvDTE.Solution)application.Solution;



我想用工程,而不是解决方案,因为我有例子中的第一个项目在网络上找到 - 如下 - 但主要是,我想有一些作品第一个

I would like to use "project", not the first project in the solution as the examples I have found on the web - as below - but mostly, I would like to have something that works first.

有关VCProject,我已经试过(关闭微软的网站,以及所有其他网站的例子):

For VCProject, I have tried (off Microsoft's web site, and all other web examples):

VCProject vcProject = (VCProject)application.Solution.Projects.Item(1).Object;
MessageBox.Show(vcProject.ProjectDirectory);

或只是...

VCProject vcProject = (VCProject)project.Object;

有关VCCodeModel,我翻译到C#的http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.vccodemodel.vccodeinclude.aspx

For VCCodeModel, I translated to c# http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.vccodemodel.vccodeinclude.aspx:

public void GetAllIncludes()
{
  VCCodeModel vcCM = (VCCodeModel)application.Solution.Item(1).CodeModel;
  foreach (VCCodeInclude vcInclude in vcCM.Includes)
  {
    MessageBox.Show(vcInclude.DisplayName);
  }    
}



均可以得到例外:

Both give exception:

"unable to cast com object of type 'system.__comobject' to interface type Microsoft.VisualStudio.VCCodeModel"
"unable to cast com object of type 'Microsoft.VisualStudio.Project.VisualC.VCProjectEngine.VCProjectShim' to type Microsoft.VisualStudio.Project.VisualC.VCProjectEngine.VCProject"

如何设置呢?最好使用项目...或 application.SelectedItems ...这可能吗?

How can I set this up ? Preferably using the "project"... or application.SelectedItems... Is it possible ?

有人可以请给我一个想法?谢谢你。

Can somebody please give me an idea? Thank you.

推荐答案

当您尝试投CodeModel到一个不同的版本VCCodeModel出现此问题。没有为每个VS版本VCCodeModel.dll。

This problem arises when you try to cast CodeModel to a different VCCodeModel version. There is a VCCodeModel.dll for each VS version.

这篇关于无法投DTE,项目或解决方案VCProject和VCCodeModel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆