Reputation: 906
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.
Upvotes: 3
Views: 2213
Reputation: 906
OK! Found a solution to this - using some obscure MSBuild syntax. Based on moswald's answer and some research online.
<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>
Upvotes: 2
Reputation: 11677
Edit: The previous version of my answer was technically correct, but not nearly as easy to set up as this one.
Open your .vcxproj file and include these lines near the bottom:
<Target Name="CopyContent" AfterTargets="Build">
<ItemGroup>
<ContentFiles Include="ContentFiles/*.png" />
</ItemGroup>
<Copy DestinationFolder="Debug/Content/"
SkipUnchangedFiles="True"
SourceFiles="@(ContentFiles)"
UseHardlinksIfPossible="True" />
</Target>
This will copy any changed files, regardless of the state of your other source files (ie, even if you don't have to compile any code, MSBuild will still make sure your content files are up-to-date).
Upvotes: 3