从 PowerShell 使用 MSBuild returns 错误 VCBuild 未加载
Using MSBuild from PowerShell returns error VCBuild not loaded
我正在尝试从 PowerShell 脚本启动一些 Visual Studio 2005 解决方案的构建,但 returns 出现此错误:
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
我真的不知道为什么会返回此消息,因为我安装了 MSVS 2005 并且安装了 .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
可能是我需要在我的系统环境路径中添加一些东西,但是错误消息没有说要添加什么,所以我在这里有点不知所措。
所以我最终完全更改了我编写的函数,这是我想出的(对我有用):
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,则在 powershell 提示符中打印构建日志。
如果您有改进代码的建议,请随时告诉我!
谢谢@David Daugherty 和@stijn!
我正在尝试从 PowerShell 脚本启动一些 Visual Studio 2005 解决方案的构建,但 returns 出现此错误:
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
我真的不知道为什么会返回此消息,因为我安装了 MSVS 2005 并且安装了 .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
可能是我需要在我的系统环境路径中添加一些东西,但是错误消息没有说要添加什么,所以我在这里有点不知所措。
所以我最终完全更改了我编写的函数,这是我想出的(对我有用):
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,则在 powershell 提示符中打印构建日志。
如果您有改进代码的建议,请随时告诉我!
谢谢@David Daugherty 和@stijn!