What Path do our PS Scripts run in?

Apr 3, 2011 at 11:30 PM

When you write an init.ps1 script, you have to do the following


param($installPath, $toolsPath, $package, $project)

Import-Module (Join-Path $toolsPath FooBar.psm1)

Notice that for my module, FooBar, I needed to join the path with the $toolsPath. So I'm wondering why that's necessary. What is the current path when this script runs? Shouldn't it already be $toolsPath? Or am I missing something (very likely that I'm missing something, I'm sure). :)



Apr 4, 2011 at 12:44 AM

Better yet, should nuget load the powershell modules as a convention?

sent from my mobile

Apr 4, 2011 at 1:44 AM

Ok I assume you are talking about modules being included in the package?

The convention is a good idea. as long as the distinction can be made between modules being deployed and modules used during the deployment.

Perhaps load all modules in a named directory? maybe "LoadAtInitModules"

Apr 4, 2011 at 1:58 AM
Not sure loading them all makes sense since we wouldn't know which ones are init vs install vs uninstall modules. I think in this case, being explicit is fine.
Apr 4, 2011 at 2:33 AM

Powershell has the notion of a module path (similar to $env:Path but for modules). In order to do Import-Module FooBar.psm1 I believe we'd need to tweak the PSMoudulePath (someone correct me if I'm wrong). Might be something we could to do in 1.3. 

Apr 4, 2011 at 4:32 AM

You don't need to tweak PSMOdulePath if you use absolute path to the .psm1 file.

Apr 4, 2011 at 4:55 AM

That's what we're trying to avoid...

Apr 4, 2011 at 5:53 AM

Why are we trying to avoid absolute path? One issue with adding PSModulePath and doing Import-Module FooBar.psm1 is that FooBar.psm1 can appear in multiple packages and so PS can import the wrong one. (I haven't tested this out, just speak out of my (possibly wrong) understanding of how Import-Module works.)