Occasionally occurring MSBUILD : error MSB3428:

Deadly 提交于 2020-12-30 03:38:51

问题


I have a PowerShell script that does the following:

  1. Upgrades an old Visual Studio solution using devenv.exe.
  2. Builds the upgraded Visual Studio solution using MSBuild.

If I run this script, I get an error stating "MSBUILD : error MSB3428: Could not load the Visual C++ component "VCBuild.exe". To fix this, 1) install the .NET Framework 2.0 SDK, 2) install Microsoft Visua l Studio 2005 or 3) add the location of the component to the system path if it is installed elsewhere."

What is strange to me is that I can successfully upgrade and build the solution if I rerun the script after seeing the error message. I've tried running the script on multiple machines, and I am seeing the error message only the first time I try executing the script. Subsequent attempts are successful.

I am using Windows 10, PowerShell version 5.1 and Visual Studio 2015 Community.

Here is the relevant snippet of code:

        $DevenvExe = 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe'
        $MsBuildExe = 'C:\Program Files (x86)\MSBuild\14.0\Bin\msbuild.exe'
        $SolutionPath = "$CurrentPath\portaudio\build\msvc\portaudio.sln"

        & $DevenvExe $SolutionPath /upgrade
        & $MsBuildExe $SolutionPath /p:Configuration=Release /p:Platform=x64 /nr:false /m:4
        if ($?) {
            Write-Host "Success"
        } else {
            # This piece of code executes, followed by the MSBUILD error
            Write-Host "PortAudio did not successfully build." -ForegroundColor Red
            Write-Host "Please refer to the Operation Manual for instructions to build PortAudio." -ForegroundColor Red
        }

What could be going on that is causing the error to happen on the first iteration of execution, but successful on all other attempts?


回答1:


For anyone that is having a similar issue:

It looks like the problem was that Devenv sometimes does not finish executing before MSBuild builds the solution. If the solution is built without upgrading, the MSBuild error message appears.This explains why subsequent attempts work (the solution only needs to be upgraded once).

Piping devenv fixes the issue:

& $DevenvExe $SolutionPath /upgrade | Out-Null

With this modification, MSBuild won't be called until Devenv finishes executing completely.




回答2:


Environment variables, no doubt!

In PS; environment variables are initialised at the start of your session.

If one is updated outside of your PS session by, say, an installer (!), the value is not updated in the current session.

However on your next run; the updated value is brought in as part of the environment variable initialisation again.



来源:https://stackoverflow.com/questions/48896010/occasionally-occurring-msbuild-error-msb3428

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!