Is there a simple way to add a path, globally (i.e. for all users on a machine), to the set of include/library directories in Visual Studio?
What I am looking for is the ability to safely add an include/library path to Visual Studio for all projects (past and future). This would be the equivalent of the INCLUDE, LIB, and LIBPATH environment variables that seem to work for command-line builds, but for some reason are completely ignored when building through Visual Studio. It must be applied to all users on a machine.
What I am NOT looking for is changing the user-specific MSBuild property sheets, Microsoft.Cpp.Win32.user.props
, as this only adds the paths for a particular user on a particular machine. Though this seems to be the recommended way to accomplishing "global" settings, it cannot be applied in my use-case:
I am involved in teaching an introduction to programming for engineers class, with roughly 1000 students per year. We have a computer lab for them to work on weekly lab quizzes, but any per-user settings/documents are purposely cleared every time a student logs out (hence we cannot rely on the user-props). As part of the course, they need to work with a custom course library for interacting with a hardware unit (hence the need to add an include/lib path). Manually adding the paths for each project is beyond what we teach students, and would become tedious given that they will create several projects per week through the term.
What we have tried:
Auxiliary
path.C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\VS
in its searches for headers and libraries. According to the docs, the folder is supposed to be for tools that are not truly part of the compilation process. This is what we currently do, but it feels wrong, and the folder location has changed with past Visual Studio versions, so may change in the future (we were stuck with VS2012 for the last 5 years because of this). We would also have to re-install the library whenever we update Visual Studio in the lab.What we could try:
The whole idea is to future-proof our workflow. What we want to do is incredibly simple: add a single header and a single library to the default search paths, and it should work with any version of Visual Studio installed on a machine. On any other system/IDE, this is a trivial task. Command-line MSBuild even supports it through Environment Variables. But for some reason, we cannot find a simple solution with Visual Studio.
Does anyone have a better idea?
Open the project's Property Pages dialog box. For details, see Set C++ compiler and build properties in Visual Studio. Select the Configuration Properties > C/C++ > General property page. Modify the Additional Include Directories property.
In Visual Studio, click Tools > Options. Expand Projects and Solutions and click Locations. The Projects location field defines the default location for storing new projects. You can change this path if you are using a different working folder.
You can add existing files to your project by right-clicking on the Project node and selecting Add > Add Files.... Alternatively, to add an entire folder, select Add > Add Existing Folder.... The file browser is shown. It lets you search your system for the required item to add.
Create a "global" property sheet that contains all the necessary changes you need, and add it to any and all new projects.
For my example, I created a property sheet called core.props
, and I saved it in the solution directory (but you could save it anywhere), and in this file, I added the includes and library names/directories (along with other settings, like specifying that Visual Studio use experimental C++ language features; specifying a precise directory for the output files; changing debug settings; etc.), and whenever I create a project that needs to make use of those settings, I just attach that property sheet to the project.
Debug x64
, but it's up to you) and "Add New Project Property Sheet" for that folderYou'll need to play around with the exact settings a bit to make sure it works the way you expect (do you need to specify a relative path or an absolute path for the libraries/includes/etc.?), but any time you create a new project, you'll only have to set that one sheet, and all the settings you need will be imported into the project. And if you need to make changes later, you'll only need to modify that one file to modify all of them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With