views:

3152

answers:

4

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!

A: 

From my understanding of using '**', the following should exclude all .svn under your $(LibrariesReleaseDir):

(The following doesn't seem to work)

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

You could try (basically from ItemGroup Element on MSDN):

<ItemGroup>
    <LibraryFiles Include="$(LibrariesReleaseDir)\**\*.*" Exclude="**\.svn" />
</ItemGroup>
sixlettervariables
Thanks for that but unfortunately it doesn't work. Think I'd already tried a few permutations around that already.I'm completely mystified by MSBuild's pattern matching!
Kieran Benton
@Kieran Benton: I too am mystified, I have some examples where stuff like that DOES work, and others where it doesn't! I'll keep researching.
sixlettervariables
@sixlettervariables: Take a look at my post below, you were very close! It actually makes much more sense to me now.
Kieran Benton
Why is this marked as the accepted answer if it doesn't work?
Shawn Miller
I just posted a solution that I think resolves some of the confusion on why this works only sometimes.
abombss
+18  A: 

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.

Thanks for starting me off on the right direction! :)

Kieran Benton
@Kieran Benton: thanks for the update, I'm going to submit a connect.microsoft.com request to clarify the MSDN documentation.
sixlettervariables
+2  A: 

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
+6  A: 

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.

abombss
BTW: This is the correct answer.
splattne