Relative paths and working directory when running deployment scripts

Mar 9, 2009 at 2:28 PM
I am wondering how about what the working directory is when tfsdeployer triggers deployment scripts. I am trying to include functions from another powershell script which is in the same location as the deployment script. From the deployment script I am also trying to reference other files with relative paths. Doesn't seem to work unless I put in fully qualified paths in each of my scripts coupling tightly to a specific box running tfsdeployer. Is there a environment variable I could use or some other means of using relative paths?
Dec 15, 2009 at 6:59 AM
Edited Dec 15, 2009 at 6:59 AM

You've probably solved the problem by now, but if anyone else is wondering: you can use $MyInvocation.MyCommand.Path to get the current execution folder.

Note that it will be null if you just debug the script from Powershell ISE, so we prefix our scripts with:

 

if ($MyInvocation.MyCommand.Path -eq $null)
{
    $currentDir = 'C:\Temp\Path\From\Where\We\Are\Debugging'
}
else
{
    $currentDir = Split-Path $MyInvocation.MyCommand.Path
}

And then, for example:

 

Import-Module -Name "$currentDir\HelpersIIS.psm1" -Force