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.
project.Object
is? – Leslileslie