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

0

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
visual-studio-2017
asked on Stack Overflow Jul 19, 2018 by bsjohnson61 • edited Jul 23, 2018 by bsjohnson61

1 Answer

0

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.

answered on Stack Overflow Jul 20, 2018 by Leo Liu-MSFT • edited Jul 24, 2018 by Leo Liu-MSFT

User contributions licensed under CC BY-SA 3.0