40

How can I construct a MSBuild ItemGroup to exclude .svn directories and all files within (recursively). I've got:

<ItemGroup> 
     <LibraryFiles Include="$(LibrariesReleaseDir)\**\*.*" Exclude=".svn" />
</ItemGroup>

At the moment, but this does not exclude anything!

Nicolas Dorier
  • 7,383
  • 11
  • 58
  • 71
Kieran Benton
  • 8,739
  • 12
  • 53
  • 77

4 Answers4

64

Thanks for your help, managed to sort it as follows:

<ItemGroup>
     <LibraryFiles Include="$(LibrariesReleaseDir)\**\*.*" 
                   Exclude="$(LibrariesReleaseDir)\**\.svn\**" />
</ItemGroup>

Turns out the pattern matching basically runs on files, so you have to exclude everything BELOW the .svn directories (.svn\\**) for MSBuild to exclude the .svn directory itself.

Michael Haren
  • 105,752
  • 40
  • 168
  • 205
Kieran Benton
  • 8,739
  • 12
  • 53
  • 77
  • 1
    @Kieran Benton: thanks for the update, I'm going to submit a connect.microsoft.com request to clarify the MSDN documentation. – user7116 Sep 16 '08 at 14:10
  • 1
    I notice that you also prefixed the Exclude value with "$(LibrariesReleaseDir)\\**\" (compared to the value in your OP). Is that significant? –  Mar 24 '11 at 19:22
12

So the issue is with chaining variables for some reason in msbuild. The following works for me, notice that I have to only use relative paths based on the MSBuildProjectDirectory variable.

<CreateItem Include="$(MSBuildProjectDirectory)\..\Client\Web\Foo.Web.UI\**\*.*"
            Exclude="$(MSBuildProjectDirectory)\..\Client\Web\Foo.Web.UI\**\.svn\**">
  <Output TaskParameter="Include" ItemName="WebFiles" />
</CreateItem>

The following does not work:

<PropertyGroup>
    <WebProjectDir>$(MSBuildProjectDirectory)\..\Client\Web\Foo.Web.UI</WebProjectDir>
</PropertyGroup>
<CreateItem Include="$(WebProjectDir)\**\*.*"
            Exclude="$(WebProjectDir)\**\.svn\**">
  <Output TaskParameter="Include" ItemName="WebFiles" />
</CreateItem>

Very strange! I just spent like 3 hrs on this one.

Ian Kemp
  • 28,293
  • 19
  • 112
  • 138
abombss
  • 476
  • 4
  • 7
3

Here's an even better way to do it, truly recursively. I can't seem to get your solution to go more than 1 level deep:

<LibraryFiles  
    Include="$(LibrariesReleaseDir)**\*.*"  
    Exclude="$(LibrariesReleaseDir)**\.svn\**\*.*"/>
Dave Markle
  • 95,573
  • 20
  • 147
  • 170
  • 1
    Does this work on the .svn\entries file as well, given that there's no dot in the filename? –  Mar 24 '11 at 19:21
1

I've run into some glitches using the Include/Exclude approach, so here's something that's worked for me instead:

<ItemGroup>
    <MyFiles Include=".\PathToYourStuff\**" />
    <MyFiles Remove=".\PathToYourStuff\**\.svn\**" />
</ItemGroup>
Anton Backer
  • 335
  • 3
  • 8