【问题标题】:Wildcard for content in an XNA content project?XNA 内容项目中内容的通配符?
【发布时间】:2010-07-13 22:24:10
【问题描述】:

我有一个 XNA 3.1 内容项目 (.contentproj),其中包含以下内容:

<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>

我想做的是能够指定一个通配符,以便编译 tiles\*.bmp - 这样当我从“瓷砖”目录。

有人知道怎么做吗?

理想情况下,解决方案会忽略“tiles”下隐藏的“.svn”目录。并且内容项目将继续在 Visual Studio 中运行。

【问题讨论】:

    标签: visual-studio msbuild xna


    【解决方案1】:

    您必须在项目定义中使用通配符:

    <ItemGroup>
      <Compile Include="tiles\**\*.BMP"
               Exclude="tiles\.svn\*">
        <Name>%(Compile.Filename)</Name>
        <Importer>TextureImporter</Importer>
        <Processor>TextureProcessor</Processor>
      </Compile>
    </ItemGroup>
    

    【讨论】:

    • 谢谢 - 效果很好。我还发现可以添加 &lt;Visible&gt;false&lt;/Visible&gt; 以防止它在 Visual Studio 中被意外破坏。
    • 实际上 - 它只对我有用,因为我目前不检查名称。似乎输出实际上被命名为“B000N800_0.xnb”、“B000N801_0.xnb”等等......(正在附加一个额外的“_0”)。
    • 我已经在本地测试过,我在 Content 目录中的 xnb 文件上没有额外的“_0”。这很奇怪
    【解决方案2】:

    我发现 Shawn Hargreaves 的一篇博文描述了如何为 XNA 1.0 执行此操作:

    Wildcard content using MSBuild

    基于此,这是我在 XNA 3.1 上所做的工作(并且不会导致那些奇怪的 _0 出现):

    创建一个单独的“tiles.proj”文件,内容如下:

    <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>
    

    在原始的“.contentproj”文件中,在&lt;/Project&gt;之前,添加:

    <Import Project="tiles.proj" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-17
      • 2015-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多