MSBuild.exe 15.0 calls cl.exe and link.exe from wrong Visual Studio directory - msbuild

I have two Visual Studio installed on my system: VS 2015 and VS 2017.
I run msbuild explicitly from the VS 2017 location:
"C:\Program Files (x86)\Microsoft Visual Studio"\2017\WDExpress\MSBuild\15.0\Bin\amd64\msbuild.exe build/binding.sln /p:Configuration=Release;Platform=x64
Since I call msbuild from the VS 2017 I expect it to take the tools from VS 2017 as well, but it does not work!
The "normal" Verbosity level shows that msbuild calls C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\cl.exe and C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\link.exe, so it takes them from the older VS 2015 that is wrong.
If I use even more verbose level (/clp:Verbosity=diagnostic) I see that msbuild takes the properties file from the wrong location as well. The message is:
Property reassignment: $(VCInstallDir_140)="C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\" (previous value: "") at C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Common.props (55,5)
The indeed properties file is located at C:\Program Files (x86)\Microsoft Visual Studio\2017\WDExpress\MSBuild\15.0\Microsoft.Cpp.Common.props.
The PATH variable is correct and does not contain anything that points to the older VS 2015. The variable VS140COMNTOOLS is unset.
Is it the expected behaviour and how can I tell msbuild to use the tools from VS 2017?

MSBuild.exe 15.0 calls cl.exe and link.exe from wrong Visual Studio directory
Please try to call the MSBuild from:
C:\Program Files (x86)\Microsoft Visual Studio\2017\WDExpress\MSBuild\15.0\Bin
and add the parameter /p:VisualStudioVersion=15.0 in the command line, like:
msbuild.exe build/binding.sln /p:Configuration=Release;Platform=x64 /p:VisualStudioVersion=15.0

I have tried the option /p:VisualStudioVersion=15.0, but it did not take effect.
Later I found what was the reason of that behaviour: my *.vcxproj file has the tag
<PlatformToolset>v140</PlatformToolset>
Once I changed it to v141 the msbuild started to take compiler and linker properly. So, it turned that msbuild first of all respects this parameter and only then probably command line options or/and PATH variable.

Related

CMake with Build Tools for Visual Studio 2019 (Just the CLI not the IDE)

I am trying to build my code with Cmake and Visual Studio 2019 Build Tools.
Note that I'm not using the IDE only the Build Tools CLI.
When I try to generate my project like this:
cmake -G "Visual Studio 16 2019" -S . -B .
CMake returns this:
Generator
Visual Studio 16 2019
could not find specified instance of Visual Studio:
C:/Program Files (x86)/Microsoft Visual Studio/2019/Community
How can I make CMake to look for the Build Tools location and not for the IDE location?
I haven't used Visual Studio in years, but according to CMake's documentation on the Visual Studio 16 2019 generator, you can use a CMake variable or an environment variable to control which instance you use.
VS 2019 supports multiple installations on the same machine. The CMAKE_GENERATOR_INSTANCE variable may be set as a cache entry containing the absolute path to a Visual Studio instance. If the value is not specified explicitly by the user or a toolchain file, CMake queries the Visual Studio Installer to locate VS instances, chooses one, and sets the variable as a cache entry to hold the value persistently.
When CMake first chooses an instance, if the VS160COMNTOOLS environment variable is set and points to the Common7/Tools directory within one of the instances, that instance will be used. Otherwise, if more than one instance is installed we do not define which one is chosen by default.
Make sure you have all of the necessary individual components selected when installing the build tools.
Make sure CMake can find the tools (e.g. add the paths to your Path variable).
As a proof of concept for my case, I added the following to my user Path variable for lib.exe, cl.exe, link.exe, etc...:
C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64
And the following path for mt.exe and rc.exe:
C:/Program Files (x86)/Windows Kits/10/bin/10.0.18362.0/x64

Error compile Visual Studio 2019 Project dll with MSBuild 2019, obfuscating with Eazfuscator NET 2018.2 in TeamCity 2020.2.2

I have this error when TeamCity Build Step compile with obfuscating a Visual Studio dll Project with MSBuild:
EXEC: error: Error occurred during processing of input file '.dll' -> Cannot load file or assembly 'zx_2cba06c4237a413ea1e8116e71ad61dc, PublicKeyToken = 6205972ab2f0fc68' or one of its dependencies. The system cannot find the specified file. C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets (5473,5): error MSB3073: The command "if /I "Release" == "Release" "C:\Program Files (x86)\Eazfuscator.NET\Eazfuscator.NET.exe" "E:\Builds\MyDll\bin\Release\MyDll.dll" --msbuild-project-path "E:\Builds\MyDll\MyDll.csproj" --msbuild-project-configuration "Release" --msbuild-project-platform "AnyCPU" --msbuild-solution-path "*Undefined*" -n --newline-flush -v 2018.2" exit with code 1.
Eazfuscator-.NET-2018.2.2 is not compatible with MSBuild 2019, the solution is use Eazfuscator-.NET-2019.1 as minimun version.

MSBuild returns non-zero errorlevel in CMD and Visual Studio Developer Command Prompt, but not PowerShell

I'm having an issue where when I try to run builds using MSBuild, I get a non-zero errorlevel (-1073741819). While researching this issue, I noticed I got this error level if I ran msbuild in the Command Prompt or VS2017 Developer Command Prompt, but not in PowerShell.
In PowerShell, if I run msbuild /? I get the normal usage information. However, in Command Prompt or VS2017 Develper Command Prompt, msbuild /? produced the same error code as above with no output. For example, in the Visual Studio Developer Command Prompt I see:
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.7.5
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
C:\Windows\System32>msbuild /?
C:\Windows\System32>echo %errorlevel%
-1073741819
However, in PowerShell I see this:
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
PS C:\WINDOWS\system32> msbuild /?
Microsoft (R) Build Engine version 15.7.180.61344 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
<<... Detailed flag options displayed here ...>>
According to PowerShell Get-Command, it's using msbuild.exe from C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe. Setting the /verbosity: flag doesn't seem to change the output.
In the event log, I'm seeing the error with the error: Exception code: 0xc0000005.
My Path:
C:\tools\ruby23\bin
C:\Program Files (x86)\Common Files\Oracle\Java\javapath
C:\windows\system32
C:\windows
C:\windows\System32\Wbem
C:\windows\System32\WindowsPowerShell\v1.0\
C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\
C:\Program Files\Microsoft SQL Server\130\Tools\Binn\
C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\
C:\Program Files\Microsoft SQL Server\130\DTS\Binn\
C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\
C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\
C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\
C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\
C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\
C:\Program Files\Microsoft SQL Server\110\Tools\Binn\
C:\Program Files\Microsoft SQL Server\120\Tools\Binn\
C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps
C:\Program Files (x86)\NuGet
C:\Program Files\Microsoft\Web Platform Installer\
C:\WINDOWS\system32
C:\WINDOWS
C:\WINDOWS\System32\Wbem
C:\WINDOWS\System32\WindowsPowerShell\v1.0\
C:\WINDOWS\System32\OpenSSH\
C:\Program Files\dotnet\
C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\
C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\
C:\ProgramData\chocolatey\bin
C:\Program Files\Git\cmd
C:\Program Files\OpenSSH-Win64
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer
C:\Program Files (x86)\Microsoft Team Foundation Server 2013 Power Tools
C:\Program Files (x86)\Microsoft Team Foundation Server 2013 Power Tools\Best Practices Analyzer\
C:\Program Files (x86)\Microsoft Team Foundation Server 2013 Power Tools\Best Practices Analyzer\
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin
C:\Users\MyUserName\AppData\Local\Microsoft\WindowsApps
C:\Users\MyUserName\AppData\Local\atom\bin
C:\Program Files\Collaborator Client
MSBuild returns non-zero errorlevel in CMD and Visual Studio Developer Command Prompt, but not PowerShell
It seems your Visual Studio Developer Command Prompt has not been initialized successfully. You can try to execute VsDevCmd.bat in the Visual Studio Developer Command Prompt:
Location: C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools
If this .bat can not be executed successfully, you can try to repair or reinstall the Visual Studio.
Update:
I'm seeing an exception code for msbuild in the Event log: Exception
code: 0xc0000005. Google hasn't produced much unfortunately
It seems the exception code 0xc0000005 is related to access violation. When you execute your command can you switch to use admin privilege? You may need to check the permission of your account. And you also need to check if Virus scanner is disabled.
Hope this helps.

How to Build a Visual Studio 2017 VSIX using MSBuild

I'm trying to use MSBuild.exe to build my Visual Studio 2017 based VSIX. I can't just build the solution as I don't want to build other projects in there. I tried using variations of the following command but these do not produce a VSIX file:
C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/Bin/MSBuild.exe" /v:normal /p:Configuration="Release" /p:Platform=AnyCPU /p:DeployExtension=false /target:Build "C:/code/Templates/Source/Boilerplate.Vsix/Boilerplate.Vsix.csproj
The solution was to add the magic /p:VisualStudioVersion=15.0 parameter like so:
C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/Bin/MSBuild.exe /p:Configuration="Release" /p:DeployExtension=false /p:VisualStudioVersion=15.0 "C:/code/Templates/Source/Boilerplate.Vsix/Boilerplate.Vsix.csproj"
go to your configuration manager and deselect the projects you do not want to build. (Right click you solution and chose configuration manager..). You can chose between release and debug in the top left as well.

Compiling clang/LLVM on win results in compile errors - how to fix?

I've stumbled upon problems installing clang/LLVM on my Win 7 64-bit machine for setting up Emscripten in my Visual Studio 2010 Setup. I was following the official howto from Emscripten at https://github.com/kripken/emscripten/wiki/Using-Emscripten-on-Windows and stumbled into problems regarding the needed compilation of clang/LLVM.
svn co http://llvm.org/svn/llvm-project/llvm/tags/RELEASE_32/final llvm
cd llvm\tools
svn co http://llvm.org/svn/llvm-project/cfe/tags/RELEASE_32/final clang
cd ..\\..
mkdir build
cmake -G "Visual Studio 10" ..\llvm
msbuild LLVM.sln /p:Configuration=Release
The result is alot of errors similiar to this one:
CUSTOMBUILD : error : error reading '10.0\VC\bin\llvm\tools\clang\test\Index\
pch-opaque-value.cpp' [c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\b
in\build\tools\clang\test\check-clang.vcxproj]
CUSTOMBUILD : error : error reading '10.0\VC\bin\llvm\tools\clang\test\Index\
pch-with-errors.m' [c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\
build\tools\clang\test\check-clang.vcxproj]
Obviously, a path starting at
'10.0\VC...' is totally invalid.. its missing the 'C:\Program Files (x86)\Microsoft Visual Studio ' in front.. (I've checked there is a file like that in test\Index\ - it is!
My question is: how do I fix that ?
a) Can I setup an additional include path that is like 'C:\folder\MS Visual ' (including space) ?
What I have tried so far:
a) Doing it from Visual Studio Prompt and normal Prompt. Using default and custom location.
b) Running MSBUILD like
msbuild LLVM.sln /p:Configuration=Release /p:"VCBuildAdditionalOptions= C:\Program Files (x86)\Microsoft Visual Studio "
c) Trying to change PATH/Systemroot.. Destroyed my systemroot in the meantime for unknown reasons (It complaimed about a wrong path like "C:\Program " and erased it obviously).
I am seriously stuck and dont know any further than these steps. Setting up an include path does not seem to help - though I'm wondering if the CMAKE stuff had problems with space's or what is going on.
Since the authors of Emscripten and probably LLVM call their windows support "experimental", I'm not the only one having troubles trying to set up LLVM/clang for later use with Visual Studio 2010 (not 2012..). I'm sorry for the bad formatting, for some reason SO won't allow me neat formatting today.. I'm using a nightly browser build though.
If you just need a build of LLVM, you can generate NMake Makefiles and build with nmake instead of msbuild. It seems that there is a quoting issue somewhere (might be CMake, CmakeLists.txt, msbuild, who knows).
On second thought, this might be a problem with environment variables. How did you set up PATH? Try from a new "Visual Studio Developer Command Prompt".