A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
You can use a Directory.Build.props file as described in Customize C++ builds. The props will be applied to every C++ project created under the folder tree containing the file. It can provide those projects with the common headers and can also be used to provide MyCode.cpp to the projects.
Folders -
For example, the Common folder contains func1.h, func2.h and MyCode.cpp (definitions of func1 and func2).
Directory.Build props contains -
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ForceImportAfterCppProps>$(MsbuildThisFileDirectory)\MyCommon.props</ForceImportAfterCppProps>
</PropertyGroup>
</Project>
MyCommon.props contains -
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>C:\Users\RLWA32\source\repos\RlwA32\MyProjects\Common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>C:\Users\RLWA32\source\repos\RlwA32\MyProjects\Common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<AdditionalIncludeDirectories>C:\Users\RLWA32\source\repos\RlwA32\MyProjects\Common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<AdditionalIncludeDirectories>C:\Users\RLWA32\source\repos\RlwA32\MyProjects\Common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
<!-- Comment out the following ItemGroup to prevent MyCode.cpp from automatic inclusion in projects -->
<ItemGroup>
<ClCompile Include="C:\Users\RLWA32\source\repos\RlwA32\MyProjects\Common\MyCode.cpp" />
</ItemGroup>
</Project>
For example, the TestCommon1 project appears like this -
Note that MyCode.cpp was automatically included in your project without any manual intervention. And it would be included in every other project created under the folder tree.
If this is undesirable, comment out the ItemGroup as described above. If you want to include MyCode.cpp in some projects but not others you would need to manually cause it to be included. An ugly way of accomplishing the would be to use the #include directive for MyCode.cpp.
For example,