从PowerShell中使用的MSBuild返回VCBuild没有加载

问题描述:

我试图从一个PowerShell脚本上几Visual Studio的推出了2005年构建解决方案的错误并返回该错误:从PowerShell中使用的MSBuild返回VCBuild没有加载

 
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 Visual Studio 2005 or 3) add the location 
of the component to the system path if it is installed elsewhere. [C:\path\to\solution\solutionToBuild.sln] 
Done Building Project "C:\path\to\solution\solutionToBuild.sln" (default targets) -- FAILED. 

Build FAILED. 

"C:\path\to\solution\solutionToBuild.sln" (default target) (1) -> 
(solutionToBuild target) -> 
    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 Visual Studio 2005 or 3) add the locati 
on of the component to the system path if it is installed elsewhere. [C:\path\to\solution\solutionToBuild.sln] 

    0 Warning(s) 
    1 Error(s) 

Time Elapsed 00:00:00.84 

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

 
PSChildName      Version  Release Product 
-----------      -------  ------- ------- 
v2.0.50727      2.0.50727.5420     
v3.0        3.0.30729.5420     
Windows Communication Foundation 3.0.4506.5420     
Windows Presentation Foundation 3.0.6920.5011     
v3.5        3.5.30729.5420     
Client       4.6.01590  394806 4.6.2 
Full        4.6.01590  394806 4.6.2 
Client       4.0.0.0      

这可能是我需要的东西添加到我的系统环境路径,但该错误信息不会说什么加,所以我在这里有点不知所措。

+1

如果我没有记错的话,这是您在启动命令行编译环境时得到的错误。 VS2005很老,我没有安装。用于在构建环境中启动此文件的bat文件可能位于C:\ Program Files文件(x86)\ Microsoft Visual Studio xx \ CommonX \ Tools \ VsMSBuildCmd.bat 当然,您可能想用任何内容替换“X”版本显示为2005 –

+0

可能是@DavidDaugherty说的。如果PATH等设置不正确,你可能不能运行'msbuild solutionToBuild.sln'。看看例如第二和第三个答案在这里:https://stackoverflow.com/questions/2124753/how-can-i-use-powershell-with-the-visual-studio-command-prompt – stijn

所以我最终改变我完全写与这里的功能是什么,我想出了(这为我工作):

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!