可以将 EnvDTE.Project 转换为 VCProject [英] Can one cast an EnvDTE.Project into a VCProject
问题描述
到目前为止,我已经看到两篇与我的问题有关的帖子.我想知道如何将 EnvDTE.Project 转换为 VCProject.
在这篇文章中,fun4jimmy 的回答正是在以下代码行中(取自他的回答):
<块引用>VCProject vcProject = project.Object as VCProject;
我尝试在我的解决方案中做同样的事情:
使用EnvDTE;使用 Microsoft.VisualStudio.VCProjectEngine;[...]私人列表<字符串>BuildAssembliesAndReturnTheirName(EnvDTE80.DTE2 dte){解决方案 sln = dte.Solution;bool isDirty = false;foreach(sln.Projects 中的项目项目){VCProject vcProject = project.Object as VCProject;配置 activeConfiguration = project.ConfigurationManager.ActiveConfiguration;foreach(vcProject.Configurations 中的 VCConfiguration vcConfiguration){//商业逻辑}}[...]
在VS中打开了一个解决方案.该解决方案包含一些 C# 项目.一切似乎都是为了让这段代码执行,直到我到达
foreach(vcProject.Configurations中的VCConfiguration vcConfiguration)
才意识到这个演员
VCProject vcProject = project.Object as VCProject;
返回空值.
谁能告诉我这是为什么?我见过 这篇文章 hveiras 建议
<块引用>每个 VS 版本都有一个 VCCodeModel.dll.
如果 VCProjectEngine.dll 也是这种情况,我该如何解决我的问题?
我已经更改了对 VCProjectEngine.dll 的引用,以便它使用 Visual Studio 2012(我正在使用的)的引用,但 vcProject
仍然为空.
VCProject 适用于 C++ 项目,为了使用与 C#/VB 项目类似的接口,您必须使用 VSProject.
有许多 VSLangProj
重载/扩展,您必须找到特定于您需要使用的版本的那个.请参阅:https://msdn.microsoft.com/en-us/library/1xt0ezx9.aspx 适用于从 2 到 100(我认为是版本 2 到版本 10)的所有 VSLangProj 接口.
I have seen two posts so far that concern my question. I am wondering how can one cast an EnvDTE.Project into a VCProject.
In this post, fun4jimmy's answer does that exactly in the following line of code (taken from his answer) :
VCProject vcProject = project.Object as VCProject;
I have tried doing the same thing in my solution :
using EnvDTE;
using Microsoft.VisualStudio.VCProjectEngine;
[...]
private List<string> BuildAssembliesAndReturnTheirName(EnvDTE80.DTE2 dte)
{
Solution sln = dte.Solution;
bool isDirty = false;
foreach (Project project in sln.Projects)
{
VCProject vcProject = project.Object as VCProject;
Configuration activeConfiguration = project.ConfigurationManager.ActiveConfiguration;
foreach (VCConfiguration vcConfiguration in vcProject.Configurations)
{
//business logic
}
}
[...]
A solution is opened in VS. The solution contains a few C# projects. Everything seems to be in order for this code to execute until I reach
foreach (VCConfiguration vcConfiguration in vcProject.Configurations)
only to realise that this cast
VCProject vcProject = project.Object as VCProject;
returns null.
Can anyone tell me why that is? I've seen this post in which hveiras suggests
There is a VCCodeModel.dll for each VS version.
If that's the case for VCProjectEngine.dll as well, how can I fix my issue?
I have changed my reference to VCProjectEngine.dll so that it uses the one for Visual Studio 2012 (what I'm working with) but vcProject
remains null.
VCProject is for C++ projects, in order to use a similar interface with C#/VB project you'll have to use VSProject.
There are a number of VSLangProj
overloads/extensions and you'll have to find the one that is specific to the version you need to use. See: https://msdn.microsoft.com/en-us/library/1xt0ezx9.aspx for all the VSLangProj interfaces from 2 through 100 (I think thats Version 2 through Version 10).
这篇关于可以将 EnvDTE.Project 转换为 VCProject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!