SolutionScripts – little scripts for the Nuget console

Sharing a Nuget package our team has been using for awhile: SolutionScripts.  It’s ridiculously simple, more of an idea than anything else.

It runs the PowerShell scripts we put in a conventional folder.  We can version those scripts with our source code.  The scripts usually expose a global function to the package manager console.

This is from the project’s readme:

When Visual Studio opens a solution, Nuget looks at each installed package for an init.ps1 script in the package’s tools directory. If that script exists it will be executed. This is the way that package authors enhance the package manager console experience for consumers of their packages.

However, sometimes developers want to add functions or custom script that will execute in the package manager console independent of a particular package. In this case, a lone developer can customize the powershell profile that the package manager console uses.

This doesn’t scale. When sharing custom scripts and global functions across an entire team for a particular project, it doesn’t make sense to edit each developer’s profile. The profile works across multiple solutions. That would also be weird, to edit a user’s profile automatically. It also doesn’t make sense to install a custom package just for each global function you wanted to register. You could do that, but you’d then have a billion highly targeted packages in your solution. Also, we like these scripts to be versioned with our source code.

With SolutionScripts you can place custom scripts in the SolutionScripts directory (which by convention sits at the same level as the packages directory). SolutionScripts will run them every time you load up the solution. If you want to refresh the scripts in the SolutionScripts directory without reloading the solution, just issue the Update-SolutionScripts command in the package manager console.

About Matt Hinze

Learning in public
This entry was posted in Tools and tagged . Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • http://twitter.com/klabranche Kevin LaBranche

    I love the idea.  I’m curious as to how your team is using it?  What kind of custom scripts are you using for this?

    • http://mhinze.com Matt Hinze

      We have some scaffolding that generates files in multiple projects.  That command is sort of annoying, so we wrapped those in global functions to make it easier.

      We have a number of environmental toggles.  Things that configure our local workstations for different scenarios and to work in different environments.  

      We have some other automation that we prefer to kick off from within studio. Like a larger testing run.

      But the sky’s the limit. If we had database migrations I’m sure we’d script those and put them here.  I’ve been on teams where we scripted the inclusion of different sets of test data, and scripted management tasks or deploy steps.. 

      • http://twitter.com/klabranche Kevin LaBranche

        Anything to make life easier and less prone to manual mistakes is great.  Thanks – Kevin