12

I have a solution of mixed VB.NET and C++ projects. When using Visual Studio 2005 you can set the "Tools->Option->Projects and Solutions->VC++ Directories" to help the compiler find your include files. When building the same solution with MSBuild I don't see how to pass these settings. The C++ won't compile without this path specified. When building this solution form Visual Studio it build perfectly.

What is the way to pass this path for MSBUild?

Edit: Looks like MSBuild doesn't pass the path (or the /u switch) to vcbuild. Starting from VCBuild instead fails on dependency.

Ron Harlev
  • 16,227
  • 24
  • 89
  • 132
  • With Visual 2010 things work more as expected since the user property directories are used. There's no more need to use environment variables – CharlesB Nov 17 '10 at 14:58
  • 1
    For latest version VS2013, see my answer in thread: http://stackoverflow.com/questions/15654002/adding-additional-library-and-include-paths-when-compiling-from-command-line/28103688#28103688 – zhifac Jan 23 '15 at 05:45

3 Answers3

13

To set the include directories, you can add them into your INCLUDE environment variable. You use the same format as in PATH env. variable - you separate paths with semicolons.

To set the library directories - you can do it in similar way, by putting them into your LIB environment variable.

To set environment variables, you simply right-click "My Computer", choose "Properties". Then you go to "Advanced" tab, and there's a button called "Environment Variables".

Or, you can run MSBuild from a BATCH script, in which case, before calling MSBuild, you can set the INCLUDE and LIB variables, like so:

set INCLUDE=C:\Libraries\LibA\Include
set LIB=C:\Libraries\LibA\Lib\x86
Paulius
  • 5,790
  • 7
  • 42
  • 47
  • 1
    If this doesn't work straight, try the fix proposed by @CharlesB below. –  Dec 07 '12 at 16:29
  • 3
    You have to add `/p:"VCBuildAdditionalOptions= /useenv"` to MSBuild arguments so that it takes the INCLUDE and LIB variables – CharlesB Feb 10 '16 at 13:53
6

...and also you may like to append %INCLUDE% and %LIB% to your variables to avoid overwriting of them

set INCLUDE=C:\Libraries\LibA\Include;%INCLUDE%
set LIB=C:\Libraries\LibA\Lib\x86;%LIB%
Gene Mayevsky
  • 61
  • 1
  • 1
5

You can use /p[roperty]:useenv=true switch to forward environment variables in newer versions of MSBuild. See full article here http://blogs.msdn.com/b/vcblog/archive/2010/01/11/vcbuild-vs-c-msbuild-on-the-command-line.aspx

Sapien2
  • 238
  • 3
  • 9