Setting up a NuGet PowerShell Profile
While NuGet alone is a pretty spectacular package management system, one of the hottest features involves the underlying PowerShell Package Console (we’ll call it PM from here out). It may look fancy and have a funky PM> prompt, but it’s still PowerShell.
Considering I use psake and live in PowerShell most of the day, I wanted to do a bit of customizing. Out of the box… urr… package, PM is barebones PowerShell.
Well, that’s pretty boring!
The question is, how would I customize things?
The answer? Setting up a profile!
Step 1: Finding the NuGet Profile
Just like a normal PowerShell installation, the $profile variable exists in PM.
Okay, that was easy. If you try to edit the file, however, it’s empty. You can either use the touch command to create an empty file, then edit it with Notepad, or simply run Notepad with the $profile path–it’ll ask you to create the file. 🙂
For an example, we’ll just pipe a bit of text into our profile and see what happens.
Now, close Visual Studio (PM only seems to load the profile when Visual Studio first starts) and relaunch it. PM should now welcome you!
Step 2: Customize, customize, customize!
Now we’re ready to add variables, setup custom paths and scripts, add some git-tastic support, and add modules (like psake). There are quite a few posts on the blog about customizing PowerShell’s environment, click here to check them out.
Remember: Since we’re using a separate PowerShell profile, be frugal with your commands and keep them "development centric". For example, I don’t load HyperV modules, Active Directory management commands, and other "non-Solution" things into the PM. Visual Studio is slow enough–don’t bog it down. :)
This is also a great opportunity to trim your profile down and break it into modular pieces (whether that be scripts or modules). Keep those profiles as DRY as possible.
A few caveats…
There do seem to be a few caveats while in the PM environment:
1. Execution, whether it’s an actual executable, a script, or piping something to more, seems to be tossed into another process, executed, and then the results returned to the PM console window. Not terrible, but something to be aware of if it seems like it’s not doing anything.
2. I can’t find a good way to manipulate the boring PM> prompt. It seems that $Host.UI is pretty much locked down. I’m hopeful that will change with further releases because not KNOWING where I am in the directory structure is PAINFUL.