Sometimes it’s useful to have a define that is set on the solution and applied to all projects in that solution. For example, you might have a define for enabling run-time checks which you don’t normally want enabled in a project, but you do want it enabled when the project is included in a test harness solution.
So, assume we have a define called ENABLE_RUNTIME_CHECKS in MyProject which we only want enabled in our project when it is included in our test harness solution.
First, open up MyProject.vcxproj in a text editor and add this line at the end of the <Project> element (just before the </Project> line):
<Import Condition="Exists('$(SolutionDir)\Solution.props')" Project="$(SolutionDir)\Solution.props" />
Do the same for your TestHarness.vcxproj
In the TestHarness folder, create a file called Solution.props with this text:
<?xml version="1.0" encoding="utf-8"?> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemDefinitionGroup> <ClCompile> <PreprocessorDefinitions>ENABLE_RUNTIME_CHECKS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <</ClCompile> </ItemDefinitionGroup> </Project>
If you only want the define to be set for specific configurations, change this line
You can set any project properties in the Solution.props file. See here for a detailed explanation of Visual Studio props files.