none
MSBuild ignores the INCLUDE variable

    Question

  • We are going to upgrade to Visual Studio 2017, however we have an issue with MSBuild on our build server. We have installed VS2017 on a number of Windows 7 computers and on random machines we observe this problem. Reinstalling Windows and VS2017 does not help. To simplify the issue, I start the VS2017 x64 Native Tools Command Prompt and then run:

    echo %PATH%

    echo %LIB%

    echo %INCLUDE%

    Then I start a Command Prompt and set the same values to these variables. When building with CL using Makefile, all works as expected. But if I run MSBuild, then I get strange error messages about missing header files:

    C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\atlmfc\include\atldef.h(69): fatal error C1083: Cannot open include file: 'errno.h': No such file or directory

    This is the value of my INCLUDE variable:

    C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\ATLMFC\include;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\winrt;


    Searching for errno.h in Program FIles (x86), I find it in C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt which is in the INCLUDE variable as can be seen above.


    Why VS2017 cannot find it when running through MSBuild even though it can find it from CL, from the native x64 build console and even though it is in the INCLUDE path? Also, it finds the atlmfc directory no matter if it is first in INCLUDE or last. How comes that this works on some computers but not on others?

    Wednesday, January 17, 2018 9:09 AM

All replies

  • Hi Soft Needed,

    Thanks for posting here.

    Have you try to install the Windows Universal CRT SDK component, which adds support for legacy Windows SDKs. You can install this using the Visual Studio Installer:

    If the problem still persists, you should change the Target SDK in the Visual Studio Project : check whether the Windows SDK version is 10.0.16299.0, or try to reinstall the SDK.

    In : Project -> test properties -> General -> Windows SDK Version

    Hope this helps.


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, January 18, 2018 11:27 AM
  • Thanks! I have Windows Universal CRT SDK installed. I am targeting Windows 7 and later, so, I have 8.1 as Windows SDK Version in the project settings. I am using the v141 toolset. I have this problem with several projects, some of which external. MSBuild simply refuses to work properly on some machines. I can build the projects from VS but not via MSBuild.
    Thursday, January 18, 2018 12:11 PM
  • In "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.Cpp.targets", the SetBuildDefaultEnvironmentVariables task overwrites the PATH, LIB, LIBPATH, and INCLUDE environment variables with values of MSBuild properties. Perhaps the build system of VS2017 does the same.

    I suggest using the verbose logging options of MSBuild to check the value of the IncludePath property.

    Thursday, January 18, 2018 2:03 PM
  • When I build with the /v:diag option, the following catches my attention:

      Task Parameter:
          ExcludedInputPaths=
              C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include
              C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\atlmfc\include
              C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\VS\include
              C:\Program Files\Windows Kits\10\Include\10.0.10240.0\ucrt
              C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\VS\UnitTest\include
              C:\Program Files (x86)\Windows Kits\8.1\Include\um
              C:\Program Files (x86)\Windows Kits\8.1\Include\shared
              C:\Program Files (x86)\Windows Kits\8.1\Include\winrt
              C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\amd64
              C:\Windows\Microsoft.NET\Framework64\v4.0.30319\
              C:\Windows\Microsoft.NET\Framework\v4.0.30319\
              C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin
              C:\Windows\Microsoft.NET\Framework\v4.0.30319\
              C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\lib\x64
              C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\atlmfc\lib\x64
              C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\VS\lib\x64
              C:\Program Files\Windows Kits\10\lib\10.0.10240.0\ucrt\x64
              C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\VS\UnitTest\lib (TaskId:23)

    Why are these paths excluded? What paths are used then?


    • Edited by Soft Needed Thursday, January 18, 2018 2:53 PM
    Thursday, January 18, 2018 2:52 PM
  • @Soft Needed, where is the MSBuild.exe called from? Are you use it from C:\Windows\Microsoft.NET\Framework\v4.0.30319? If yes, please try to use the MSBuild.exe from C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin, If you still get the same error, could you please share us a test sample project and some steps, so that we could reproduce this issue.

    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, January 22, 2018 10:00 AM