envdte - C# Get Configuration from DTE -
i'm trying build kind of custom configuration manager visual studio 2013. i've created vspackage menucommand , run in visual studio experimental instance. projects of current solution use this:
public static envdte80.dte2 getactiveide() { // instance of 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 project; if (project == null) { continue; } list.add(project); } return list; }
when try access configurationmanager of project, 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 (project) works fine, because if comment out row[1] , row[2] list of project names.
don't know how else project configuration, because posts found use configuration manager.
1) not use marshal.getactiveobject envdte instance extension loaded, return running instance. use getservice(typeof(envdte.dte))
2) navigate projects of solution recursively, not linearly. see howto: navigate files of solution visual studio .net macro or add-in.
3) envdte.project.configurationmanager can return null if project doesn't support configuration. c# , vb.net project should work, though. c++ projects use different project model (vcconfiguration). other projects maybe don't support configuration programmatically.
Comments
Post a Comment