开发者

Wildcard for content in an XNA content project?

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

<ItemGroup>
开发者_C百科<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.


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>


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" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜