Freigeben über


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.

Comments

  • Anonymous
    January 25, 2005
    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?

  • Anonymous
    January 25, 2005
    Source Code Control operations will be completely ignorant of InProject=false items.

  • Anonymous
    January 25, 2005
    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.

  • Anonymous
    January 25, 2005
    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>

  • Anonymous
    January 25, 2005
    That makes sense doesn't it? :)

    I think I need to look at MSBuild some more. If only I had the time...

  • Anonymous
    January 26, 2005
    So, it seems that it's the equivalent of the property VSHPROPID_IsHiddenItem and not VSHPROPID_IsNonMemberItem on items. Am I correct?

  • Anonymous
    January 26, 2005
    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...

  • Anonymous
    January 26, 2005
    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.


  • Anonymous
    May 02, 2013
    I am told this is now <Visible>false</Visible>

  • Anonymous
    June 04, 2013
    FYI <InProject>False</InProject> <Visible>False</Visible> works only in C# projects, but not in C++ projects