0

I need to call out to a powershell function defined in a file in a separate folder. That function needs to use a dll located in the same folder. Is there any easy way to do this?

Details:

Structure:

  • build\build.ps1
  • tools\myTool\fileWithFunction.ps1
  • tools\myTool\someDll.dll

build.ps1 has Include "...\tools\myTool\fileWithFunction.ps1"

It calls a function in that file. That function needs to load someDll.dll. I could pass the location of the folder (toos\myTool) in the function call, but was wondering if there's a way by which the function in fileWithFunction can figure out the location of the dll by itself (assuming that it's always in the same folder).

3
  • stackoverflow.com/questions/801967/… Commented Apr 28, 2014 at 11:46
  • I actually have \tools\psake\psake calling build\build.ps1. Using the code in that post is giving me \tools\psake instead of \tools\myTool. Commented Apr 28, 2014 at 11:53
  • * ... \psake called by build\build.ps1 Commented Apr 28, 2014 at 12:05

2 Answers 2

0

Use $PSScriptRoot, this should get what you need.

Sign up to request clarification or add additional context in comments.

Comments

0

And if you're on PowerShell V2 (hopefully you're on at least v3), put this in fileWithFunction.ps1

$ScriptDir = {Split-Path $MyInvocation.ScriptName –Parent}

Then access the dir like so:

"ScriptDir is $(&$ScriptDir)"

The reason the scriptblock is used is to ensure safety when dot sourcing script files.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.