I'm trying to build some kind of custom Configuration Manager for Visual Studio 2013. I've created a VSPackage MenuCommand and currently run it in an visual studio experimental instance. To get the projects of the current solution i use this:
public static EnvDTE80.DTE2 GetActiveIDE()
{
// Get an instance of currently running Visual Studio IDE.
var dte2 = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.12.0");
return dte2;
}
public static IList<Project> Projects()
{
Projects projects = GetActiveIDE().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;
}
list.Add(project);
}
return list;
}
When I try to access the ConfigurationManager of a project, I get a NullRefernceException:
var projects = Projects().OrderBy(p => p.Name).ToList();
foreach (var project in projects)
{
DataRow row = solutionConfigurationData.NewRow();
row[0] = project.Name;
row[1] = project.ConfigurationManager.ActiveConfiguration.ConfigurationName;
row[2] = project.ConfigurationManager.ActiveConfiguration.PlatformName;
}
The COM-Object itself (project) works fine, because if comment out row[1] and row[2] I get a list of all project names.
Don't know how else to get the project configuration, because all the posts i found use the configuration manager.