Is it possible to add a custom include directory to Visual Studio C++
with the help of just environment variables.
I'm afraid the answer is negative.It's not possible to achieve this goal only with Environment Variable.
- Please check this: When compiling the project in VS, if the compiler encounters an #include statement, it tries to open the specified file. If the file is an absolute path, it only tries to load from that specific path.
If the file is a relative path, it tries to load from the directory of the file being compiled first. If the file is not found in the same folder as the cpp file, the compiler tries each of the paths in its 'Include Directories' list to find the file.
- And in VS IDE, we can set the
Include Directories
or Additional Include Directories
to set the search path.So if I have a header file Test.h
, and I use statement like #include <AbsolutePath\Test.h>
, the compiler can find the header.
If i use statement like #include <Test.h>
, the header file can't be found until I set the search path. In this situation, I can set the Additional Include Directories
for all both debug and release to make the compiler find the header file (Test.h locates in Company folder):

Note: But one point we should know is most of the time, when we change the settings in Project=>Properties we actually is modifying the project file.(xx.vcxproj).
As you mentioned above, we can't make any change to project files, so
we can't achieve the goal by this way. Instead i think you can try
using
Directory.build.props
file.
Create a Directory.Build.props file, move it to root directory of your project folder. For me: C:\Users\userName\source\repos
folder. Add the content like below into it:
<Project>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>C:\Company;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
</Project>
We can put the header file into the C:\Company
(We can specify our folder in this way) folder and the compiler can find it. Also, we're not doing any change to Solution, project or source file.
Please let me know if it's helpful:) Any feedback feel free to contact me.