1

I have an XNA 3.1 content project (.contentproj) with the following:

<ItemGroup>
<Compile Include="tiles\B000N800.BMP">
  <Name>B000N800</Name>
  <Importer>TextureImporter</Importer>
  <Processor>TextureProcessor</Processor>
</Compile>
<Compile Include="tiles\B000N801.BMP">
  <Name>B000N801</Name>
  <Importer>TextureImporter</Importer>
  <Processor>TextureProcessor</Processor>
</Compile>
(... and so on ...)
</ItemGroup>

What I'd like to do is be able to specify a wildcard so that tiles\*.bmp gets compiled instead - so that I don't have to keep re-synchronising the content project when I add and remove textures from the "tiles" directory.

Does anyone know a way to do this?

Ideally the solution would ignore the hidden ".svn" directory, under "tiles". And also the content project would continue to work in Visual Studio.

Andrew Russell
  • 26,924
  • 7
  • 58
  • 104

2 Answers2

3

You'll have to use wildcard in your item definition :

<ItemGroup>
  <Compile Include="tiles\**\*.BMP"
           Exclude="tiles\.svn\*">
    <Name>%(Compile.Filename)</Name>
    <Importer>TextureImporter</Importer>
    <Processor>TextureProcessor</Processor>
  </Compile>
</ItemGroup>
Julien Hoarau
  • 48,964
  • 20
  • 128
  • 117
  • 1
    Thanks - that worked nicely. Also I've found that `false` can be added to prevent it from being accidentally clobbered in Visual Studio. – Andrew Russell Jul 13 '10 at 12:39
  • Actually - it's only working for me because I'm not checking the names at the moment. It seems the output is actually being named "B000N800_0.xnb", "B000N801_0.xnb" and so on... (an additional "_0" is being appended). – Andrew Russell Jul 13 '10 at 12:47
  • I've tested it locally and I don't have an additional "_0" on my xnb files in Content directory. That's strange – Julien Hoarau Jul 13 '10 at 13:18
2

I found a blog post by Shawn Hargreaves that describes how to do this for XNA 1.0:

Wildcard content using MSBuild

Based on that, here is what I did which works with XNA 3.1 (and doesn't cause those weird _0 to appear):

Create a separate "tiles.proj" file with the following content:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<ItemGroup>
  <WildcardContent Include="tiles\**\*.BMP" Exclude="tiles\.svn\*">
    <Importer>TextureImporter</Importer>
    <Processor>TextureProcessor</Processor>
  </WildcardContent>
</ItemGroup>

<Target Name="BeforeBuild">
  <CreateItem Include="@(WildcardContent)" AdditionalMetadata="Name=%(FileName)">
    <Output TaskParameter="Include" ItemName="Compile" />
  </CreateItem>
</Target>
</Project>

And in the original ".contentproj" file, right before </Project>, add:

<Import Project="tiles.proj" />
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Andrew Russell
  • 26,924
  • 7
  • 58
  • 104