Solution Scoped Init.ps1

Apr 19, 2011 at 3:51 PM


After watching the "NuGet In Depth" talk at MIX11 (great, you can watch it here), I started to write some powershell scripts for some of my projects (with RegisterTabExpansion the possibilities are just... impressive).

The 'Nuget Package' method to add helpers is great but sometimes I just want to define a shortcut function (for exemple to restore a database and regenerate codesmith templates in one call).

These shortcuts are only useful in my solution scope, it feels a bit wrong to have to generate a package just for that.

Is it possible (or is there a convention?) to make the Package Manager Console (should be the Visual Studio Console IMHO) loading a simple powershell script that doesn't belong to a package?

It could be at $(SolutionDir)/tools/init.ps1 for exemple...

Thanks in advance,


Apr 19, 2011 at 4:10 PM

No, but it’s a great suggestion. I think there might already be a bug for something similar, but you’d have to search around for it. I’d love for the console to load scripts at a machine level too! For example, it’d be nice if PS scirpts in %AppData%\NuGet\Tools\ were automatically loaded in our console.

If there’s no bug for this already, can you create one?

Apr 19, 2011 at 4:30 PM
Edited Apr 19, 2011 at 4:44 PM

Yep, I'll take a look in the bugs and add one if neccesary.

And thanks for your work, it's making mine less hard and more fun :)


EDIT: and here's the bug:

Apr 19, 2011 at 4:46 PM

Not sure if I fully understand, but doesn't profile script meet your needs here?

Apr 19, 2011 at 6:08 PM
Edited Apr 19, 2011 at 6:08 PM

Good idea, I'll use that as a workaround for the moment but to keep things clean the Nuget scoped scripts are would still be useful:

It's more clean to have solution specific scripts inside the solution folder.

Even for the machine level scripts, some commands are available inside de PM console and not in the regular PS console so the script could cause problems outside VS.

Apr 19, 2011 at 6:18 PM

Note that the profile script for NuGet is different from the profile script of the PS console. So you won't have collison issue with the regular PS conosle.

Personally I don't find it worth adding new concept to NuGet just for this scenario. If you want to have solution specific scripts, you can implement the logics in your profile script to execute the solution-specific scripts.

Apr 19, 2011 at 6:25 PM

oups didn't noticed that sorry, so you're right there's just the solution specific scripts missing and it can be made from the profile. Thanks

Apr 19, 2011 at 7:12 PM
I agree with dotnetjunky here.

Having the init.ps1 set up powershell modules is actually a pretty awesome way to get reuse and versioning out of your powershell scripts. I don't believe it is wrong to create a package just for that. That would be like saying SolutionFactory or MvcScaffolding is wrong.

May 3, 2011 at 9:50 PM

So how do scripts get into these folders? Let's work out a spec for the feature here together and we'll consider it.

May 4, 2011 at 1:05 AM

Isn't it possible to create a package with an Init.ps1 that reads all modules in a PowerShellModules directory next to your MySolution.sln file?