Welcome to MSDN Blogs Sign in | Join | Help

Hack the Build: Hide Items from Visual Studio Solution Explorer

Jomo Fisher -- Custom MSBuild projects and targets files that you write typically have ItemGroups to contain lists of files. For example,

<ItemGroup>
 <MyFiles Include="a.txt"/>
</ItemGroup>

When you fire up VS with the above code in a project you'll find that "a.txt" shows up in the solution explorer. Depending on how you intend these items to be used you might be delighted by this or you might be annoyed. You'll be annoyed if the ItemGroup is a private implementation detail and should not be in the user's face.

If this has happened to you, try this:

<ItemGroup>
 <MyFiles Include="a.txt">
  <InProject>false</InProject>
 </MyFiles>
</ItemGroup>

The InProject metadata will not affect the build at all. It just tells Visual Studio that you don't want the item displayed in Solution Explorer.

This posting is provided "AS IS" with no warranties, and confers no rights.

Published Tuesday, January 25, 2005 1:51 PM by Jomo Fisher
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Hack the Build: Hide Items from Visual Studio Solution Explorer

By using the <InProject> XML element, what happens with SCC? Will the item be sent to SCC or will it be completely excluded from the project?
Tuesday, January 25, 2005 2:44 PM by Thierry Kormann

# re: Hack the Build: Hide Items from Visual Studio Solution Explorer

Source Code Control operations will be completely ignorant of InProject=false items.
Tuesday, January 25, 2005 2:48 PM by Jomo Fisher

# re: Hack the Build: Hide Items from Visual Studio Solution Explorer

Is there any particular reason that was implemented as a sub-element rather than an attribute. It seems like that sort of thing should be an attribute of the file rather than a child of it.
Tuesday, January 25, 2005 3:35 PM by David Stone

# re: Hack the Build: Hide Items from Visual Studio Solution Explorer

In MSBuild, all Item metadata (not just InProject) is represented in the form of sub-elements rather than attributes.
The reason for this decision was so that metadata could have embedded XML. For example,

<MyItems Include="a.txt">
<MyCustomItemInfo>
<Color>Orange</Color>
<Smell>Peppermint</Smell>
</MyCustomItemInfo>
</MyItems>
Tuesday, January 25, 2005 3:41 PM by Jomo Fisher

# re: Hack the Build: Hide Items from Visual Studio Solution Explorer

That makes sense doesn't it? :)

I think I need to look at MSBuild some more. If only I had the time...
Tuesday, January 25, 2005 6:55 PM by David Stone

# re: Hack the Build: Hide Items from Visual Studio Solution Explorer

So, it seems that it's the equivalent of the property VSHPROPID_IsHiddenItem and not VSHPROPID_IsNonMemberItem on items. Am I correct?
Wednesday, January 26, 2005 1:23 PM by Thierry Kormann

# re: Hack the Build: Hide Items from Visual Studio Solution Explorer

Oups, my mistake. It's the other way around. It seems that the InProject element is the equivalent of VSHPROPID_IsNonMemberItem. Sorry for those two comments...
Wednesday, January 26, 2005 1:25 PM by Thierry Kormann

# re: Hack the Build: Hide Items from Visual Studio Solution Explorer

Actually, when InProject=False, the item is not read into the IVsHierarchy structure at all. The item is completely skipped during read.

This posting is provided "AS IS" with no warranties, and confers no rights.


Wednesday, January 26, 2005 1:36 PM by Jomo Fisher

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker