> hmmm pre-conditions are evaluated before a task is executed, not when the script is loaded.
> I don't see anything obviously wrong with your script but try this - replace the calls to the "CheckForRunningMongo" function with the code [((Get-Process "mongod" -ea SilentlyContinue)) -eq $null}] or try adding "()" to the end of the function call ["CheckForRunningMongo()"]
> I think your precondition code is always returning true because you are not invoking the function and returning a result but simply returning a reference to the function.
> But I could be wrong. :)
> Sent from my iPhone
> On Oct 29, 2011, at 10:44 AM, bswift <brettsw...@gmail.com> wrote:
> > I'm running a .net project, and am doing some integration tests to the
> > database. I want to run mongo both on my CI server (teamcity) and
> > locally. The problem is that locally I have a database installed,
> > and on the server I want it to run in process, or for anyone checking
> > out the code to not have to install mongo.
> > What I want to wrap my tests with an initial "StartMongo" task and end
> > it with a "StopMongo" task. I'm trying to use preconditions for
> > this.
> > My first trial was to set a boolean property, and on the first "Init"
> > task, see if mongo is running, set that property and use that property
> > in the preconditions. It seems like preconditions are evaluated when
> > the script is loaded, if it's running off a property variable.
> > I can't use the code that I have here, because the "StopMongo"
> > precondition will ALWAYS return true.
> > Any ideas on how I can get this to work? As you see in the script
> > below, I have the precondition commented out on the StopMongo task to
> > output the variable that I want to use to see if mongo is running, it
> > always evaluates to false.
> > Thanks!
> > properties {
> > $root_dir = Resolve-Path .
> > $test_dir = "$root_dir\test\"
> > $lib_dir = "$root_dir\lib\"
> > $temp_dir = "$root_dir\temp"
> > $solution_name = "ToolRegistry"
> > $solution_file = "$solution_name.sln"
> > $mongoDb_dir = "$root_dir\temp\data\db\"
> > $mongoDbExe = "$root_dir\lib\MongoDbExe\bin\mongod.exe"
> > $mongoDbParams = "--dbpath $mongoDb_dir"
> > $killMongoProcess = $false
> > }
> > #move to functions file
> > function Get-FrameworkDirectory(){
> > $
> > ([System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory() )
> > }
> > function CheckForRunningMongo{
> > ((Get-Process "mongod" -ea SilentlyContinue)) -eq $null
> > }
> > task default -depends StartMongo, StopMongo
> > task StartMongo -Depends Init -precondition { return
> > CheckForRunningMongo} {
> > write-host "starting mongo $mongoDbExe"
> > Start-Process -FilePath $mongoDbExe -ArgumentList $mongoDbParams
> > write-host -foregroundcolor green "Mongo Process id :" $mongoPid.Id
> > $killMongoProcess = $true
> > }
> > task StopMongo {# -precondition {return CheckForRunningMongo} {
> > write-host -foregroundcolor green "Kill Mongo Process?
> > $killMongoProcess "
> > Stop-Process -processname mongod
> > }
> > --
> > You received this message because you are subscribed to the Google Groups "psake-users" group.
> > To post to this group, send email to psake-users@googlegroups.com.
> > To unsubscribe from this group, send email to psake-users+unsubscribe@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/psake-users?hl=en.