Search code examples
visual-studiomsbuildbuild-toolsvisual-studio-2017-build-tools

How to build SLN file from the command line using MSVC build tools


I am trying to build the Hunspell project on GitHub with MSVC 2017 build tools: https://github.com/hunspell/hunspell

The project have a msvc folder containing a Hunspell.sln and libhunspell.vcxproj files (I am interested in the library)

My setup:

  • Windows 10
  • MSVC2017 build tools (15.9.3)
  • Windows 10 Kit: 10.0.17763.0

If I open the "x86 Native Tools Command Prompt for VS 2017" and try to build the solution I get the following error:

>msbuild libhunspell.vcxproj
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 2018/12/01 6:01:18 PM.
Project "c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj" on node 1 (default targets).
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Platforms\Win32\PlatformToolsets\v140_xp\Toolset.targets(36,5): warning MSB8003: Could not find WindowsSdkDir_71A variable from the registry.  TargetFrameworkVersion or PlatformToolset may be set to an invalid version number. [c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(366,5): warning MSB8003: Could not find WindowsSDKDir variable from the registry.  TargetFrameworkVersion or PlatformToolset may be set to an invalid version number. [c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj]
InitializeBuildStatus:
  Touching "Debug\libhunspell\libhunspell.tlog\unsuccessfulbuild".
PreBuildEvent:
  echo N | copy /-Y ..\src\hunspell\hunvisapi.h.in ..\src\hunspell\hunvisapi.h
  :VCEnd
  Overwrite ..\src\hunspell\hunvisapi.h? (Yes/No/All): N
          0 file(s) copied.
ClCompile:
  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\CL.exe /c /I..\src\hunspell /I. /ZI /nologo /W4 /WX- /Od /Oy- /D WIN32 /D _DEBUG /D _WINDOWS /D _USRDLL /D HUNSPELL_STATIC /D _CRT_SECURE_NO_WARNINGS /D _USING_V110_SDK71_ /D_MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"Debug\libhunspell\\" /Fd"Debug\libhunspell\libhunspell.pdb" /Gd /TP /wd4706 /wd4251 /wd4267 /analyze- /errorReport:queue ..\src\hunspell\csutil.cxx 
csutil.cxx
c:\development\hunspell\hunspell-1.7.0\src\hunspell\csutil.cxx(84): fatal error C1083: Cannot open include file: 'windows.h': No such file or directory [c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj]
Done Building Project "c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj" (default targets) -- FAILED.


Build FAILED.

"c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj" (default target) (1) ->
(CheckWindowsSDK71A target) ->
  C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Platforms\Win32\PlatformToolsets\v140_xp\Toolset.targets(36,5): warning MSB8003: Could not find WindowsSdkDir_71A variable from the registry.  TargetFrameworkVersion or PlatformTool set may be set to an invalid version number. [c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj]


"c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj" (default target) (1) ->
(PrepareForBuild target) ->
  C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(366,5): warning MSB8003: Could not find WindowsSDKDir variable from the registry.  TargetFrameworkVersion or PlatformToolset may be set to an invalid version number. [c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj]


"c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj" (default target) (1) ->
(ClCompile target) ->
  c:\development\hunspell\hunspell-1.7.0\src\hunspell\csutil.cxx(84): fatal error C1083: Cannot open include file: 'windows.h': No such file or directory [c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj]

The important part in the above is the following: Cannot open include file: 'windows.h'

It seems like my console is set up correctly when looking at the INCLUDES variable:

echo %INCLUDE%
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt

I have tried many options like running as follow, with no luck:

> msbuild libhunspell.vcxproj /p:AdditionalIncludeDirectories="C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um"

I have also added the full path to the "um" and "shared" (for winapifamily.h) folders to the <AdditionalIncludeDirectories> property manually in the vcxproj file. This works for the static libs, but I had to add the <AdditionalIncludeDirectories> to the <ResourceCompile> step. For the dlls (Release_Dll, etc) linking did not work since I don't know how to fix this (yet).
The above feels wrong, I do not think that the solution can be to hack a project file for the compiler to know where its own files are.

Any help in this regard will be appreciated.

Note: I do not have Visual Studio IDE installed, most SO questions around this question involve steps to solve the issue by changing settings in Visual Studio. This does not apply to this question.

PS: I have no experience with msbuild or the build tools. I normally use the Qt Creator IDE for building with MSVC compiler.


Solution

  • How to build SLN file from the command line using MSVC build tools

    You should install the Individual components VC++ 2015.3 v14.00 (v140) toolset for desktop via build tools.

    According to the error log:

    TargetFrameworkVersion or PlatformToolset may be set to an invalid version number

    When we open the libhunspell.vcxproj with notepad, we could to know following properties:

      <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_dll|x64'" Label="Configuration">
        <ConfigurationType>DynamicLibrary</ConfigurationType>
        <PlatformToolset>v140_xp</PlatformToolset>
        <UseOfMfc>false</UseOfMfc>
        <CharacterSet>MultiByte</CharacterSet>
      </PropertyGroup>
    

    So, to resolve this issue, we need install the toolset v140_xp. To accomplish this, Open the build tool, switch to the Individual components tab and select VC++ 2015.3 v14.00 (v140) toolset for desktop:

    enter image description here

    After that, I can build the peoject successfully:

    enter image description here

    Hope this helps.