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' '2.0.0.2000'
chew 'xunit' '1.8.0.1549'
chew 'Pester' '1.0.1'
chew 'psake' '4.0.1.0'
chew 'Giles' '0.1.1.3'

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 2.0.0.2000'.
Successfully installed 'xunit 1.8.0.1549'.
Successfully installed 'Pester 1.0.1'.
Successfully installed 'psake 4.0.1.0'.
Successfully installed 'Giles 0.1.1.3'.

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

Featured

  • Kubernetes for Developers

    Microsoft's Dan Wahlin previews his introductory "Kubernetes for Developers" session at Visual Studio Live! San Diego 2026, explaining how developers can get past the Kubernetes learning curve by starting locally, mastering Pods first, and using Services to make containerized applications reliably accessible.

  • VS Code Keeps Eye on Costs in v1.126 Update

    Visual Studio Code 1.126 adds session-level Copilot cost information, continuing Microsoft's recent focus on helping developers monitor and manage usage-based GitHub Copilot billing.

  • Open VSX 1.0.0 Puts Focus on Open Extension Registry for VS Code Ecosystem

    Eclipse Open VSX has reached 1.0.0, highlighting its role as a vendor-neutral registry for VS Code-compatible extensions.

  • Infragistics Puts MCP Toolchain at Center of Ultimate 26.1

    Infragistics Ultimate 26.1 introduces the Ignite UI Enterprise MCP toolchain for AI-assisted app development across Angular, React, Web Components and Blazor.

Subscribe on YouTube