2
votes

I have an MSBuild script that I want to call from a PowerShell script as part of a deployment process. If I call the build script via a bat file all works well. If I do the exact same thing in PowerShell I get CS1668 error looking for wierd and wonderful paths that dont exist on my machine. I know I am getting into the MSBuild script as these errors are occuring from within the MSBuild script targets (logging output is showing this). The bat file and the PowerShell script reside in the same place, right next to the build script.

Errors:

error CS1668 : Warning as error : Invalid search path 'C:\Program Files\Microsoft Visual Studio 8\VC\AtlMfc\Lib' specified in 'LIB environment variable' -- 'The system cannot find the path specified. ' error CS1668 : Warning as error : Invalid search path 'C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Lib' specified in 'LIB environment variable'-- 'The system cannot find the path specified. '

I have checked and neiter of these paths do NOT exist on my machine. Why would running from PowerShell change what paths MSBuild look for?

Thanks in advance

RhysC

EDIT- adding in code: NB the name of the MSBuild script is AutomatedDebug.build POWERSHELL SCRIPT:

#Begining of script
$CurrentPath = Split-Path (Split-Path $myinvocation.mycommand.path )
#Assign the Build script paths. 1 is for building and testsing, 1 is for deployment (to keep things clean)
$MSBuildScriptBuildAndTestPath = $CurrentPath + "\Tools\AutomatedDebug.build"
$MSBuildScriptDeployPath = $CurrentPath + "\Tools\Deploy.build"

#Run the automated build with tests
Write-Host "*** Run the automated build with tests ***" 
C:\Windows\Microsoft.NET\Framework\v3.5\MSbuild.exe $MSBuildScriptBuildAndTestPath "/t:AllTests" "/l:FileLogger,Microsoft.Build.Engine;logfile=AllTests.log"
if($LastExitCode -ne 0)
{
    throw "AllTests failed"
}
Write-Host "*** FINISHED: Run the automated build with tests ***" 

Bat File

@C:\Windows\Microsoft.NET\Framework\v3.5\MSbuild.exe AutomatedDebug.build /t:AllTests /l:FileLogger,Microsoft.Build.Engine;logfile="AllTests.log"
@pause
enter code here
3

3 Answers

3
votes

Ok, what is actually happening is that I have dowloaded the Powershell Community Extensions (http://pscx.codeplex.com) many moons ago and there is a Environment.VisualStudio2005.ps1 file in there that adds EnvVars that dont exist. This is (I assume) becuase i dont use VS2005. I have commmented this out and all is well. I have tried to look for the 2008 equivilent but dint have too much luck. To be honest i dont use powershell to its full potential so i doubt i even need the PSCX on my machine anyway.

Thanks guys for your help.

0
votes

It is most likely due to how you are passing parameters into the MSBuild script. There are some key parameter parsing differences between CMD and PowerShell and by using a batch file, you are implicitly using CMD's parameter parsing engine to hand off the parameters to MSBuild. If you post the command line you're using, one of the PowerShell gurus here can probably help debug where the parameters are getting confused.

0
votes

I am wondering, basically you get "Warning as error" here. You can either try turning off treating warnings as errors (I mean, having a lib path which doesn't exist doesn't sound that bad to me) or you'll let your scripts print out the respective environment variables (using echo %LIB% and $Env:LIB respectively) from the scripts and look for differences.

However, since the envvars for VS aren't set globally by default (that's why there are the three Visual Studio command prompts) you have to set all variables somewhere. If you're doing this within the scripts you may have a typo somewhere?