Currently, game data and image files are included in the Engine project. In this lesson, we’ll move them out.
They aren’t code, so it makes sense to get them out of a class library project. This will also help if we add more files. This technique always copies every file in the folders – giving us one less thing for us to remember (or forget).
We’re going to do this with a “post-build event”
Step 1: Create GameFiles folder
Create this new folder under your solution’s top-level directory
Step 2: Move files from Engine directory to GameFiles directory
Cut-and-paste GameData folder
Cut-and-paste Image folder
Step 3: Create post-build event to copy files
In the WPFUI project, right-click and select “Properties”.
On the properties screen, select the “Build Events” tab.
Copy this line into the “Post-build event command line box”. This command will run after each time we build the project/solution, copying all the files and folders in the GameFiles folder to the project’s output folder – the location where the executable version of the program is located.
xcopy “$(SolutionDir)GameFiles\*.*” “$(ProjectDir)$(OutDir)” /s /y
Step 4: Test the game
Rebuild the solution and make sure the games still runs correctly.
PREVIOUS LESSON: Lesson 19.2: Identifying refactoring targets