Reputation: 49482
I have an MSBuild script in which I create a list of source code files something like this:
<ItemGroup>
<ZipSourceFiles Include="Project1\**\*.*" Exclude="**\bin\**;**\obj\**;**\.svn\**" />
<ZipSourceFiles Include="Project2\**\*.*" Exclude="**\bin\**;**\obj\**;**\.svn\**" />
<ZipSourceFiles Include="Project3\**\*.*" Exclude="**\bin\**;**\obj\**;**\.svn\**" />
<ZipSourceFiles Include="Project4\**\*.*" Exclude="**\bin\**;**\obj\**;**\.svn\**" />
<ZipSourceFiles Include="MyApp.sln" />
</ItemGroup>
This works, but I would rather not cut and paste the same exclude pattern each time, but declare it once and reuse it. However, my attempts to put the exclude patterns into an ItemList or the whole pattern into a Property both failed miserably. What is the correct msbuild syntax to do this?
Upvotes: 1
Views: 227
Reputation: 4772
Try this:
<PropertyGroup>
<ExcludePattern>**\bin\**;**\obj\**;**\.svn\**</ExcludePattern>
</PropertyGroup>
<ItemGroup>
<ZipSourceFiles Include="Project1\**\*.*" Exclude="$(ExcludePattern)" />
<ZipSourceFiles Include="Project2\**\*.*" Exclude="$(ExcludePattern)" />
<ZipSourceFiles Include="Project3\**\*.*" Exclude="$(ExcludePattern)" />
<ZipSourceFiles Include="Project4\**\*.*" Exclude="$(ExcludePattern)" />
<ZipSourceFiles Include="MyApp.sln" />
</ItemGroup>
Upvotes: 2