.NET Framework Bookmark and Share   
 index > MSBuild > CreateItem recursively on a directory excluding another directory?
 

CreateItem recursively on a directory excluding another directory?

I have a problem. I have 2 directory structures. Which effectively mirror each other and I need to reconcile them as a matter of process. I need to list everything in directory A that isn't in directory B,recurisively.

So I create an item for directory B but how do I work it into the exclude for item A? I need that recurisive directory structure but the syntax is giving me grief since I have to shift it to match directory A. Any ideas?

Lou Machado

I figured it out. As Mike said the the directory paths don't match. However through some monkeying around I managed to use the exclude by taking advantage of the recursive dir property. Check this out:

<
CreateItem Include="$(SolutionRoot)\directory2\**\*.*">

<Output TaskParameter="Include" ItemName="Directory2Files"/>

</CreateItem>

<CreateItem Include="$(SolutionRoot)\directory1\**\*.*" Exclude="@(Directory2Files->'$(SolutionRoot)\directory1\%(RecursiveDir)%(Filename)%(Extension)')">

<Output TaskParameter="Include" ItemName="Directory1Files"/>

</CreateItem>

I have to say it, I love MSBuild!

  • Marked As Answer byLou Machado Tuesday, September 08, 2009 4:10 PM
  •  
Lou Machado
Hi Lou,

How about writing a custom task to do this job? The input of the taskwill betwo item list and the output will be one item list of different items.

In order to write a custom task, please refer to: http://msdn.microsoft.com/en-us/library/t9883dzc.aspx.



Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Hongye Sun
Hi Lou,

Basically you could take item A which contains all files in directory A and subtract item B (all files in directory B) from it. You then get an item C that only contains files that are not listed in item B, i.e. that are not in directory B. In MSBuild you can do it as follows:

< CreateItem Include = " @(DirectoryA) " Exclude = " @(DirectoryB) " >
<
Output TaskParameter = " Include " ItemName = "FilesNotInDirectoryB " />
</
CreateItem >
ACKH
I don't think that will work as the paths will be different so the Exclude will not match the items. A custom task is probably required.
Mike Fourie

I figured it out. As Mike said the the directory paths don't match. However through some monkeying around I managed to use the exclude by taking advantage of the recursive dir property. Check this out:

<
CreateItem Include="$(SolutionRoot)\directory2\**\*.*">

<Output TaskParameter="Include" ItemName="Directory2Files"/>

</CreateItem>

<CreateItem Include="$(SolutionRoot)\directory1\**\*.*" Exclude="@(Directory2Files->'$(SolutionRoot)\directory1\%(RecursiveDir)%(Filename)%(Extension)')">

<Output TaskParameter="Include" ItemName="Directory1Files"/>

</CreateItem>

I have to say it, I love MSBuild!

  • Marked As Answer byLou Machado Tuesday, September 08, 2009 4:10 PM
  •  
Lou Machado

You can use google to search for other answers

Custom Search

More Threads

• How to get the built assemblies
• Unit Tests and MSBuild
• error MSB4057
• /target switch does not work as advertised
• trouble referencing System.Management.Automation
• Build
• Plugging in the SDC WiX tasks to Team Build
• COM Visibility VS2005
• How do I avoid a Trget from being skipped?
• Strange problem with dependencies