【问题标题】:Using MSBuild from PowerShell returns error VCBuild not loaded从 PowerShell 使用 MSBuild 返回错误 VCBuild not loaded
【发布时间】:2017-07-18 13:42:05
【问题描述】:

我正在尝试通过 PowerShell 脚本在一些 Visual Studio 2005 解决方案上启动构建,但它返回此错误:

MSBUILD:错误 MSB3428:无法加载 Visual C++ 组件“VCBuild.exe”。要解决此问题,1) 安装 .NET Framework 2.0 SDK,2) 安装 Microsoft Visual Studio 2005 或 3) 添加位置 如果组件安装在其他位置,则将其复制到系统路径。 [C:\path\to\solution\solutionToBuild.sln] 完成构建项目“C:\path\to\solution\solutionToBuild.sln”(默认目标)——失败。 构建失败。 "C:\path\to\solution\solutionToBuild.sln" (默认目标) (1) -> (解决方案构建目标)-> MSBUILD:错误 MSB3428:无法加载 Visual C++ 组件“VCBuild.exe”。要解决此问题,1) 安装 .NET Framework 2.0 SDK,2) 安装 Microsoft Visual Studio 2005 或 3) 添加 locati 如果将组件安装在其他位置,则将其放在系统路径中。 [C:\path\to\solution\solutionToBuild.sln] 0 个警告 1 个错误 经过时间 00:00:00.84

我真的不知道为什么会返回此消息,因为我安装了 MSVS 2005 并安装了 .NET V2:

PSChildName 版本发布产品 ----------- ------- ------- -------- v2.0.50727 2.0.50727.5420 v3.0 3.0.30729.5420 Windows 通信基础 3.0.4506.5420 Windows 演示基础 3.0.6920.5011 v3.5 3.5.30729.5420 客户端 4.6.01590 394806 4.6.2 全 4.6.01590 394806 4.6.2 客户端 4.0.0.0

可能是我需要在我的系统环境路径中添加一些东西,但是错误消息并没有说明要添加什么,所以我在这里有点不知所措。

【问题讨论】:

  • 如果我没记错的话,这是您在不启动命令行构建环境时遇到的错误。 VS2005 很旧,我没有安装。用于在构建环境中启动它的 bat 文件可能位于 C:\Program Files (x86)\Microsoft Visual Studio xx\CommonX\Tools\VsMSBuildCmd.bat 当然你会想用显示的任何版本替换“X”迎接 2005 年
  • 可能是@DavidDaugherty 所说的。如果 PATH 等设置不正确,您可能不能只运行“msbuild solutionToBuild.sln”。看看例如这里的第二个和第三个答案:stackoverflow.com/questions/2124753/…

标签: powershell msbuild visual-studio-2005 vcbuild


【解决方案1】:

所以我最终完全改变了我编写的函数,这就是我想出的(对我有用):

function Build-MSVS2K5Solution {
    param (
        [parameter(mandatory=$true)][validateNotNullOrEmpty()][String] $solutionToBuild,
        [parameter(mandatory=$true)][validateNotNullOrEmpty()][Array] $solutionEnv,
        [parameter(mandatory=$false)][validateNotNullOrEmpty()][Switch] $autoOpenBuildLog = $false
    )

    process {
        $wshell = New-Object -ComObject Wscript.Shell
        $wshell.Popup("Please wait while solutions are being rebuilt.",0,"Building Solution...",0x1)
        cd "C:\"
        if (Test-Path "C:\Windows\Microsoft.NET\Framework\v2.0.50727")
        {
            $msBuild = "C:\Windows\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe"
        }

        $buildArgs = $solutionToBuild + (Get-ChildItem $SolutionToBuild | Where { $_.Name -like "*.sln" }) +" /p:Configuration=Debug /p:Platform=Win32"
        $buildLog = [Environment]::GetFolderPath("Desktop") + "\buildlog.log"

        foreach ($solEnv in $solutionEnv ) {
            $itemPath = "env:" + $solEnv.Substring(0, ($solEnv.ToString().LastIndexOf("=") ) )
            $itemValue = $solEnv.Substring( ($solEnv.ToString().LastIndexOf("=")+1) )
            Set-Item -Path $itemPath -Value $itemValue
        }


        Write-Output "Building $buildArgs..."
        Start-Process -FilePath $msBuild -ArgumentList $buildArgs -RedirectStandardOutput $buildLog

        if ($autoOpenBuildLog) 
        {
            Write-Output "Getting content of : $buildLog"
            Get-Content $buildLog -Tail 1 -Wait
        }
    }
}

$solutionEnv = "envName=envValue", "envName2=envValue2", "etc.=etc."
Build-MSVS2K5Solution -SolutionToBuild "C:\Path\to\solution\" -solutionEnv $solutionEnv -autoOpenBuildLog

它并不完美,但它确实有效。基本上,我发送解决方案的路径,函数找到解决方案“* .sln”(我知道解决方案目录只包含一个)。它设置以字符串形式接收的环境变量,然后开始构建,如果调用了 $autoOpenBuildLog,则 buildLog 会打印在 powershell 提示符中。

如果您有改进代码的建议,请随时告诉我!

谢谢@David Daugherty 和@stijn!

【讨论】:

    猜你喜欢
    • 2022-12-18
    • 2015-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-26
    相关资源
    最近更新 更多