I'm trying to launch a build on a few Visual Studio 2005 solutions from a PowerShell Script and it returns this error:
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
I really have no idea why this message is returned since I have MSVS 2005 installed and I have .NET V2 installed:
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
It might be that I need to add something to my system environment path but the error message doesn't say what to add, so I'm a little bit at a loss here.
So I ended up changing the function I wrote completely and here's what I came up with (which worked for me):
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
It's not perfect, but it works. Basically, I send the path to the solution, the function finds the solution "*.sln" (I know the solution direrctory only contains one). It sets the environment variables received in a string, then starts the build and if $autoOpenBuildLog is called, the buildLog is printed in the powershell prompt.
Feel free to let me know if you have suggestions to improve the code!
Thank you @David Daugherty and @stijn !