dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.21k stars 1.35k forks source link

msbuild fails building vcpkg as 'NT\SYSTEM' (SysWOW64 issue) #4107

Closed daef closed 5 years ago

daef commented 5 years ago

Steps to reproduce

:: fetch vcpkg source
> git clone https://github.com/Microsoft/vcpkg.git
:: impersonate as service (needs pstools)
> psexec -i -s cmd.exe
:: try to bootstrap
> cd vcpkg && bootstrap-vcpkg
[...]

Building vcpkg.exe ...

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(314,5): error MSB4018: The "CL" task failed unexpectedly. [D:\nightly\vcpkg\toolsrc\vcpkglib\vcpkglib.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(314,5): error MSB4018: System.TypeInitializationException: The type initializer for 'Microsoft.Build.Utilities.FileTracker' threw an exception. ---> System.IO.FileNotFoundException: The system cannot find the file specified. (Exception from HRESULT: 0x80070002) [D:\nightly\vcpkg\toolsrc\vcpkglib\vcpkglib.vcxproj]
https://github.com/Microsoft/vcpkg/issues/5248
[...]

Expected behavior

Microsofts vcpkg.exe gets built

Actual behavior

Error MSB4018 stops the build

Environment data

> whoami
nt authority\system

I cross posted this issue to vcpkg since I don't know where the correct place to fix this resides: https://github.com/Microsoft/vcpkg/issues/5248

rainersigwald commented 5 years ago

Can you get more detailed logs? Usually problems related to running as local system have to do with the location of the TEMP folder, and that's plausibly the case here, but there's not enough information to tell.

daef commented 5 years ago

In the meantime I've found that not only setting env:TMP to point somewhere else solves my problem, but Microsoft/vcpkg explicitly clears environmental changes before calling msbuild which makes exactly this impossible.

rainersigwald commented 5 years ago

Ok, if that's the case, I don't think there's much of anything MSBuild can do to help here--we can't control TEMP ourselves, and Windows has the bad behavior of putting it behind a wow32-redirected folder when running under local system.