$script:MyInvocation.MyCommand.Definition

It works also in cases where scripts/functions are calling each other.
Without the $script prefix, it would instead give you the calling function OR the path if there was no parent function.
With the prefix, it always yields the directory of the script
This commit is contained in:
Alexander Karatarakis 2018-01-22 18:18:53 -08:00
parent 62c8626f4d
commit a5fe308ea3
5 changed files with 5 additions and 5 deletions

View File

@ -13,7 +13,7 @@ function findExistingImportModuleDirectives([Parameter(Mandatory=$true)][string]
return
}
$scriptsDir = split-path -parent $MyInvocation.MyCommand.Definition
$scriptsDir = split-path -parent $script:MyInvocation.MyCommand.Definition
. "$scriptsDir\VcpkgPowershellUtils.ps1"
$profileEntry = "Import-Module '$scriptsDir\posh-vcpkg'"

View File

@ -4,7 +4,7 @@ param(
[Parameter(Mandatory=$False)][string]$withVSPath = ""
)
$scriptsDir = split-path -parent $MyInvocation.MyCommand.Definition
$scriptsDir = split-path -parent $script:MyInvocation.MyCommand.Definition
$vcpkgRootDir = & $scriptsDir\findFileRecursivelyUp.ps1 $scriptsDir .vcpkg-root
Write-Verbose("vcpkg Path " + $vcpkgRootDir)

View File

@ -3,7 +3,7 @@ param(
[Parameter(Mandatory=$true)][string]$Dependency
)
$scriptsDir = split-path -parent $MyInvocation.MyCommand.Definition
$scriptsDir = split-path -parent $script:MyInvocation.MyCommand.Definition
. "$scriptsDir\VcpkgPowershellUtils.ps1"
Write-Verbose "Fetching dependency: $Dependency"

View File

@ -6,7 +6,7 @@ param(
$withVSPath = $withVSPath -replace "\\$" # Remove potential trailing backslash
$scriptsDir = split-path -parent $MyInvocation.MyCommand.Definition
$scriptsDir = split-path -parent $script:MyInvocation.MyCommand.Definition
$VisualStudioInstallationInstances = & $scriptsDir\findVisualStudioInstallationInstances.ps1
if ($VisualStudioInstallationInstances -eq $null)
{

View File

@ -3,7 +3,7 @@ param(
)
$scriptsDir = split-path -parent $MyInvocation.MyCommand.Definition
$scriptsDir = split-path -parent $script:MyInvocation.MyCommand.Definition
$vswhereExe = (& $scriptsDir\fetchDependency.ps1 "vswhere") -replace "<sol>::" -replace "::<eol>"
$output = & $vswhereExe -prerelease -legacy -products * -format xml