3

I'm working on a game engine that stores content (audio files, config files, textures, etc.) in a Content subfolder in the project. Master files live in $(ProjectDir)/Content, and need to get copied to the individual target directories ("Debug/Content" and "Release/Content") whenever the master files are changed.

I'm using a post-build event that works pretty well:

XCOPY "$(ProjectDir)Content" "$(TargetDir)Content" /I /D /E /C /Y

Unfortunately it only works if a build & link happens - i.e. I have to "touch" some .cpp file to trigger it, otherwise VS never executes the post-build XCOPY command.

Is there a way to get it to always run a command on Build(F6) or Run(F5)? Or a better way to handle content files in the project maybe? Hoping to be able to tweak Content files quickly then run the game to preview.

This is in Visual Studio 2012 professional.

4

2 回答 2

3

编辑:我的答案的前一个版本在技术上是正确的,但设置起来不像这个那么容易。

打开您的 .vcxproj 文件并在底部附近包含以下行:

<Target Name="CopyContent" AfterTargets="Build">
  <ItemGroup>
    <ContentFiles Include="ContentFiles/*.png" />
  </ItemGroup>
  <Copy DestinationFolder="Debug/Content/"
        SkipUnchangedFiles="True"
        SourceFiles="@(ContentFiles)"
        UseHardlinksIfPossible="True" />
</Target>

这将复制任何更改的文件,而不管您的其他源文件的状态如何(即,即使您不必编译任何代码,MSBuild 仍将确保您的内容文件是最新的)。

于 2012-12-13T23:32:44.753 回答
2

好的!找到了解决方案 - 使用一些晦涩的 MSBuild 语法。基于 moswald 的回答和一些在线研究。

<Target Name="CopyContent" AfterTargets="Build">
  <ItemGroup>
    <DeployFileGroup 
      Include="**\*.json;**\*.png;**\*.wav;**\*.mp3;" />
  </ItemGroup>
  <Copy SourceFiles="@(DeployFileGroup)" 
    DestinationFiles="@(DeployFileGroup->'$(TargetDir)%(RecursiveDir)\%(Filename)%(Extension)')" 
    SkipUnchangedFiles="True" UseHardlinksIfPossible="True"/>
</Target>
于 2012-12-14T01:38:08.960 回答