Compartilhar via


How To: Exclude Multiple Files From a Wildcard

We got the following question on our internal conversion discussion alias today:

Is there a way to exclude two or more items from an ItemGroup using the “exclude” attribute without using a wildcard?

It turns out the way to do this wasn't clear from our existing MSDN Documentation. Brett, our documentation writer, has a fix in the queue for the next MSDN refresh, but in the mean time here is the answer from Dan:

<ItemGroup>

          <Compile Include="*.cs" Exclude="a.cs;b.cs"/>

</ItemGroup>

[ Author: Neil Enns ]

Comments

  • Anonymous
    June 20, 2006
    <a href='http://www.yahoo.com'></a> http://www.insurance-top.com/auto/">http://www.insurance-top.com/auto/ <a href='http://www.insurance-top.com'>auto insurance</a>. <a href="http://www.insurance-top.com ">Insurance car</a>: car site insurance, The autos insurance company, compare car insurance. [url]http://www.insurance-top.com/car/[/url] [link=http://www.insurance-top.com]insurance quote[/link] from site .

  • Anonymous
    July 09, 2006
    The comment has been removed

  • Anonymous
    November 06, 2006
    Ok interesting that this works:  <ServerServiceBinaries      Include="$(ServerServiceDirectory).dll;      $(ServerServiceDirectory).exe;      $(ServerServiceDirectory).txt;      $(ServerServiceDirectory).sys;      $(ServerServiceDirectory).config;      $(ServerServiceDirectory).bat"      Exclude=".pdb;      $(ServerServiceDirectory)AppServer.vshost.exe;      $(ServerServiceDirectory)AppServer.vshost.exe.config;"      /> But this does not <ServerServiceBinaries      Include="$(ServerServiceDirectory)."      Exclude=".pdb;      $(ServerServiceDirectory)AppServer.vshost.exe;      $(ServerServiceDirectory)AppServer.vshost.exe.config;"      /> The Exclude *.pdb will not exclude or ADD to the selection filter. I'm assuming that when you make the wildcard statement . that you can no longer exclude?   Is this a by design if so it kind of sucks.   Eric

  • Anonymous
    February 14, 2007
    You can do this (I just figured it out): <ServerServiceBinaries     Include="$(ServerServiceDirectory)."     Exclude="$(ServerServiceDirectory).pdb;     $(ServerServiceDirectory)**.vshost.;     /> Apparently "" doesn't mean "anything" in msbuild.

  • Anonymous
    March 24, 2007
    insurance geico <a href= http://ourl.org/geico_insurance >geico  insurance</a> [url=http://ourl.org/geico_insurance]geico  insurance[/url]

  • Anonymous
    April 06, 2007
    insurance geico <a href= http://geico-insurance.supermmm.info > geico insurance</a> [url=http://geico-insurance.supermmm.info] geico insurance[/url]

  • Anonymous
    August 07, 2007
    I found a nuanced little bug in MSBuild 2.0.50727.832 today. My development time is balanced between Linux and Windows.  Certain habits, like directory slashes, carry between the platforms. Like much of the Windows stack the internal commands for dealing with paths don't mind when / is used, so I simply use / as my directory separator even when making MSBuild scripts. This afternoon I discovered that  <ItemGroup>    <WebAppFiles       Include="$(RootDir)/project/thingie/"       Exclude="$(RootDir)/project/thingie//.js"       />  </ItemGroup> fails to exclude the .js files from the item group, while  <ItemGroup>    <WebAppFiles       Include="$(RootDir)projectthingie**"       Exclude="$(RootDir)projectthingie**.js"       />  </ItemGroup> behaves exactly as one would expect it to and removes all of the files ending in .js from the WebAppFiles item set.

  • Anonymous
    August 07, 2007
    Actually, the / was not the problem.  It was that RootDir was defined to have a / in it (or a , didn't matter).  When the path is ..//project/thingie/** the exception processing did not work.  When it is ../project/thingie/** it does. So, still a bug, but not the one I thought it was!

  • Anonymous
    August 08, 2007
    Ok, I take it back.  Both are problems.  A match pattern of Exclude="$(RootDir)/project/thingie/omitthis/** fails,  A match mattern of Exclude="$(RootDir)projectthingieomitthis**" works to prune the 'omitthis' directory tree. There be bugs in the handling of vs / within MSBuild ItemGroup handling.

  • Anonymous
    May 29, 2009
    PingBack from http://paidsurveyshub.info/story.php?title=msbuild-team-blog-how-to-exclude-multiple-files-from-a-wildcard

  • Anonymous
    June 02, 2009
    PingBack from http://uniformstores.info/story.php?id=45159

  • Anonymous
    June 09, 2009
    PingBack from http://weakbladder.info/story.php?id=5314

  • Anonymous
    June 16, 2009
    PingBack from http://lowcostcarinsurances.info/story.php?id=518

  • Anonymous
    June 17, 2009
    PingBack from http://patioumbrellasource.info/story.php?id=1282

  • Anonymous
    October 22, 2009
    @Lionel: I ran into the same problem trying to exclude *.vstemplate. I was able to fix this by adding the wildcard at the end: .vstemplate. There seems to be a bug when the extension is more than 3 characters long, and the ItemGroup task behaves different when using the wildcard.

  • Anonymous
    January 10, 2010
    Because Unzip command fails for 0-sized files and it seems there is no solution for that, I need an alternative solution. Because I can not delete these files, is there any way to exclude files with size == 0 ?? Thanks Riga

  • Anonymous
    August 22, 2012
    Ahhh, the curse of the incorrect slash! I just had a similar issue where wildcard includes were working but excludes were not working. I was using "/" instead of "".... duh.... I'm not sure why MSBuild allows the forward slash to function at all for file paths.

  • Anonymous
    August 26, 2015
    This way worked for me: <ItemGroup> <SourceDir Include="$(MSBuildThisFileDirectory)." Exclude="$(MSBuildThisFileDirectory).svn**"/>  </ItemGroup>