views:

708

answers:

3

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
A: 

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.

Lee
I'm pretty sure its not the parameters because the there are only the build target and logger sepecified, both of which are being accepted as the target is running and it is shown in the specified log file. thanks tho.
RhysC
Since the errors are about the contents of environment variables using cmd or powershell shouldn't make a difference here. Parsing within the shell has nothing to do with envvars, as those are simply copied to a spawned process.
Joey
My knoweledge of Sheel stuff is all bad but i assumed it was a $path varliable of something of the sort. Johannes; are you saying that they should be the same? any ideas why its failing?
RhysC
A: 

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?

Joey
Ok thanks. I dont explictly set env varibles in any of the scripts so is it possible that the cmd line and powershell look for differnt environment variables?
RhysC
Ok i am l;ooking into my profile.ps1 and it looks like there may be some vs2005 env vars in there... the VS8 path should have been a hint as i am using vs2008(vs9)
RhysC
By default neither shell uses different environment variables as those are, well, _environment_ variables, not shell variables, so independent of the program using them. Each process has a local copy of the global variables which it can modify and extend to its liking (which is what SET in cmd or $Env:Foo = "Bar" in PS does), but that remains entirely within the application, although the process's copy of those variables gets propagated to spawned processes so they inherit their caller's variables. Clean up the paths in your $PROFILE and it should work, I guess.
Joey
+2  A: 

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.

RhysC