Open Source.NET

Clean Up NuGet Dependencies With Chewie

Chewie is a domain-specific language that uses PowerShell to tame NuGet installations.

Many developers are tired of dealing with XML. If you're one of them, and don't like the XML configuration files NuGet scatters around during package installation, Chewie might be the tool for you. Created by EricRidgeway and BobbyJohnson, Chewie is a set of PowerShell scripts which define a small DomainSpecificLanguage (DSL) designed to bundle your NuGet dependencies. It gathers your NuGet packages into a single bundle that you can easily manage.

The easiest way to get Chewie is to use its NuGet package. If you install Chewie through Visual Studio, you'll have access to a couple of new commands in the Package Manager Console (PMC).

If you're not in Visual Studio and want to use Chewie, you must make sure that NuGet is in your path. This is needed because Chewie has to use NuGet or the install-package command in the PMC.

If you want to have Chewie available to all your projects through PowerShell, copy the files to a central location and import chewie.psm1 into your PowerShell profile using the Import-Module command. You can edit your profile by entering notepad $profile into the PowerShell command-line.

If you don't want to add Chewie to your profile, just manually import the chewie.psm1 module into your PowerShell session.

Once Chewie's installed, you'll have two new PowerShell commands: Initialize-Chewie and Invoke-Chewie. The first will create a file named .NugetFile and put in some boilerplate configuration. The second will parse the .NugetFile and execute the commands therein. Now that you have Chewie and a simple .NugetFile, there are three basic commands in the grammar to know:

  • source
    The source command will set the default feed used to pull NuGet packages.
  • install_to
    By default, NuGet installs packages to the .\packages\<Package>.<Version> folder. The install_to command is used to specify the root folder for your packages. So if you specified install_to ‘lib', your packages will go to .\lib\<Package> when installed.
  • chew
    The chew command installs the package and allows for an optional version and source parameter. The source parameter overrides the source command so that you can specify an alternate feed for that particular package.

Chewie will keep installed package layout a little cleaner than the default NuGet layout by allowing you to specify which directory to use, and it doesn't use the version number in the folder names.

Taking a real example of a .NugetFile:

  install_to  'Packages'
chew 'Moq' '4.0.10827'
chew 'Rx-Main' '1.0.10621'
chew 'NLog' ''
chew 'xunit' ''
chew 'Pester' '1.0.1'
chew 'psake' ''
chew 'Giles' ''

Then, in the PowerShell Prompt, I can run Chewie:

  PS  C:\dev\PowerStudio> Invoke-Chewie
Successfully installed 'Moq 4.0.10827'.
Successfully installed 'Rx-Main 1.0.10621'.
Successfully installed 'NLog'.
Successfully installed 'xunit'.
Successfully installed 'Pester 1.0.1'.
Successfully installed 'psake'.
Successfully installed 'Giles'.

And my file system now has the packages installed:

PS C:\dev\PowerStudio>  ls .\Packages


Directory: C:\dev\PowerStudio\Packages

Mode              LastWriteTime     Length Name
----              -------------     ------ ----
d----       12/11/2011   9:38 AM          Giles
d----       12/11/2011   9:37 AM          Moq
d----       12/11/2011   9:38 AM          NLog
d----       12/11/2011   9:38 AM          Pester
d----       12/11/2011   9:38 AM          psake
d----       12/11/2011   9:37 AM          Rx-Main
d----       12/11/2011   9:38 AM          xunit

Chewie is a creative example of using PowerShell to create an elegant DSL. I highly recommend you look through the scripts to understand how Chewie processes the .NugetFile. It will be well worth your time.

About the Author

Ian Davis is the Master Code Ninja for software architecture and development consulting firm IntelliTechture. A C# MVP, Davis is an expert on the .NET Tramework and co-organizer of the Spokane .NET User Group who frequently speaks at industry events. He spends most of his free time as an open source author and advocate, publishing and working on many open source projects.

comments powered by Disqus


  • What's New in Visual Studio 2019 v16.5 Preview 2

    The second preview of Visual Studio 2019 v16.5 has arrived with improvements across the flagship IDE, including the core experience and different development areas such as C++, Python, web, mobile and so on.

  • C# Shows Strong in Tech Skills Reports

    Microsoft's C# programming language continues to show strong in tech industry skills reports, with the most recent examples coming from a skills testing company and a training company.

  • Color Shards

    Sharing Data and Splitting Components in Blazor

    ASP.NET Core Version 3.1 has at least two major changes that you'll want to take advantage of. Well, Peter thinks you will. Depending on your background, your response to one of them may be a resounding “meh.”

  • Architecture Small Graphic

    Microsoft Ships Preview SDK, Guidance for New Dual-Screen Mobile Era

    Microsoft announced a new SDK and developer guidance for dealing with the new dual-screen mobile era, ushered in by the advent of ultra-portable devices such as the Surface Duo.

  • How to Create a Machine Learning Decision Tree Classifier Using C#

    After earlier explaining how to compute disorder and split data in his exploration of machine learning decision tree classifiers, resident data scientist Dr. James McCaffrey of Microsoft Research now shows how to use the splitting and disorder code to create a working decision tree classifier.

.NET Insight

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.

Upcoming Events