Share Files Between Projects

From Valve Developer Community
Jump to: navigation, search

In the creation of a mod, sometimes it is necessary to have a "global" file that both the "client" and "hl" projects can use. To set a file that can be updated from both projects, just follow these steps:

  1. Browse to your mod folder, e.g. C:\MyMods\Mod\ and go to the src directory. In this example, we are going to open the game_shared directory and create a new .cpp file.
  2. Create a text file by right-clicking the folder and clicking New -> Text Document. Rename it mysharedfile.cpp.
  3. Open up the solution file game.sln in VS.NET.
  4. Under the client project create a new folder under Source Files. Name it mod or whatever you prefer.
  5. Right-click the "mod" folder and select Add -> Add Existing Item.
  6. Browse to your C:\MyMod\Mod\src\game_shared directory and find mysharedfile.cpp. Double-click it to add it to your project.
  7. Repeat steps 4-6 for the hl project.

The point of doing this is that both projects now share the same file. This means it does NOT matter which project you use to edit your file, they will be updated and compiled by both. You can use this method for any type of file you want to share.

Note:You do not have to put your shared files in game_shared, it's just easier to keep organized that way. Feel free to create a whole new subfolder. Your includes might be a bit different then, e.g. #include <mycustomfolder/header.h>.