This project is read-only.

Accessing UIHierarchy to configure a file's build action

Mar 8, 2011 at 6:52 PM

Is it possible currently to access the EnvDTE.UIHierarchy directly from studioshell or is that something that may be looked into in the future?

Specifically I'm trying to test configuring a build action for a particular file and I use the EnvDTE.UIHierarchy to access and configure that In a way that works something like this

EnvDTE.DTE CurrentVSRef = (EnvDTE.DTE )System.Runtime.InteropServices.Marshal.GetActiveObject(ACTIVE_OBJECT);
EnvDTE.UIHierarchy UI = (EnvDTE.UIHierarchy)CurrentVSRef.Windows.Item(EnvDTEConstants.vsWindowKindSolutionExplorer).Object;

ProjectItem projectitem = (ProjectItem)UI.UIHierarchyItems.Item(filename);
projectitem.Properties.Item("BuildAction").Value = action;

Is there a way to do this in studio shell?

Mar 8, 2011 at 7:59 PM

The UIHeirarchy isn't modeled in StudioShell yet.  Not sure it will be. 

However, project items and their properties are.  You can get the equivalent of the ProjectItem reference using the get-item cmdlet:

 

$item = get-item dte:\solution\projects\<projectname>\<filename>

$item.Properties | where{ $_.name -match 'buildaction' } | set-itemproperty -name "Value" -value $action


A little cumbersome at the moment.  I'd like to model these project item properties as paths, the way that the general visual studio properties are available under dte:/properties.  Something like:

set-item -path dte:/solution/projects/myproject/program.cs/properties/buildaction -value $action

Just haven't gotten to it.

Mar 8, 2011 at 9:31 PM

Crap your quick. Thanks for the info and congrats on the release. StudioShell is full of awesome sause!

Mar 11, 2011 at 10:23 PM

OK, so I went ahead and added this to the 1.0.1 release.  :)

Let me know how it goes!