Wednesday, December 08, 2010

Another way to deploy/share code and code snippets… NuGet

Daniel Cazzulino's Blog - How to create lightweight reusable source code with NuGet

“Sometimes, you just have a reusable helper that you bring in to every project (i.e. an argument validation thingy, or the static reflection stuff, useful extension methods, and so on). You don't always need them all, they are generally single-file utilities, and having a Common.dll looks overkill or dumb.

Loose source file sharing has always been problematic, though: no packaging and versioning mechanism (unlike an assembly), hard to integrate with source control systems (SVN has external repository mappings, but nothing like that exists in TFS or Mercurial, AFAIK), and so on. I tried source files reuse before, with somewhat poor results.

In a recent project I wanted to reuse (again) that darn useful Guard.cs file. But I set to do it differently this time, and see if my "dream" for lightweight loose source file reuse could still be achieved.

Two key technologies enable some pretty cool and robust source file reuse nowadays:

  • NuGet: unless you've been living under a rock, you probably heard all the big names talking about it. I'll save the introductions. But for our particular case, it's the perfect mechanism to deploy simple "content" files to the user's project. When you "install" the loose source file package, you essentially get the file added automatically to the project. When you "uninstall" it, the file gets removed. Clean, x-copy.
  • Mercurial: versioning of loose files can be a bit of nightmare. If everyone has a copy of the file, how do we evolve the helpers, how to we build a community around it? Mercurial and in particular CodePlex implementation, allows dead-easy forking, updating and contributing back (sending "pull requests") to the original author.

Deploying code snippets with our package

Now that's it! Just re-building the package is enough to get the changes in, and sure enough, our code snippets will get deployed and removed as necessary.

pagesnap…”

This is a great walk through of creating a NuGet package to share source code and code snippets.

 

Related Past Post XRef:
Vsi Builder 2010 (for those things you can’t use Visx’s for… snippets, old style VS addins, etc)

A “Hello [NuGet] World”
NuPack = NuGet (Think “A New way to Get libraries”)
I “Nu” I needed you… NuPack v1 Developer Preview/CTP 1 Released (Think, “Where have you been all my dev life… finally an package management system/installer for .Net”)

SQL Compact 4.0 CTP + NuPack = Painless project package plus’age
One man’s debugging tale - How he hunts down a bug in NuPack, with his friends WinDbg and Reflector
New background on NuPack - A little about how it came about

No comments: