.NET and Open Source: better together


  • Join Us on Facebook!
  • Follow Us on Twitter!
  • LinkedIn
  • Subcribe to Our RSS Feed

Using NuGet with BlogEngine.NET

nuget-logo2If you are .NET developer you no doubt heard about NuGet – this little package manager rapidly becoming a big deal in .NET open source community. There is a lot to like about it, and if you want to learn more go subscribe to Phil, Scott Hanselman or Scott Guthrie blogs to stay on top. To me interesting question is how NuGet can help me with daily development, for example, how can I apply it to build things for BlogEngine? Lets check this out.

Business as usual

vsfilesA while ago I did a widget that shows visitor info in the sidebar. It got out of date, and I decided to update it for BE 2.0. I downloaded old source code from my own blog, it is a ZIP file that I had to extract locally. Inside I found “widgets” folder, dragged it over “widgets” folder in BE 2.0 project and content of widgets got merged. Simple enough, right? And this is how it works in BlogEngine world, you download/unzip/merge files into your blog’s directory. To upgrade widget I added couple references to namespaces that changed in 2.0 and call it done. Ok, how do I package it for distribution? Easy – create folder called “widgets”, inside it create folder called “Feedjit” and add updated source files there. Then right-click “widgets” folder –> send to –> compressed (zipped) and I’m done. Resulting ZIP file is what other people will download, unzip and merge to their blogs to be able to use Feedjit. That not hard but obviously screams for automation. And we could build unzip/merge process into BlogEngine pretty easily, but there is so much better way.

Lets get NuGety

What I want is to package my widget into .nupkg format used by NuGet. Lets do it step by step.

1. Create working directory, say c:\packages and add “Feedjit” folder to it. Inside it create folder “content” – you can think of it as your blog root directory.

2. Copy folder structure created to build standard ZIP file and move it to that “content” folder. You should get: c:\packages\Feedjit\content\widgets\Feedjit and 4 source files inside it.

3. Download NuGet.exe and move it to c:\packages.

4. Now create spec file for the widget, it looks like this:

<?xml version="1.0" encoding="utf-8"?> 
    <description>Feedjit lets you see friends and visitors as they arrive on your blog or website.</description> 

and save it as Feedjit.nuspec in the C:\packages\Feedjit (at same level as “content”).

5. Open command prompt, change to c:\packages and run this line:

nuget pack feedjit\feedjit.nuspec

The result should look something like this:



Congratulation, we created our first NuGet package! But… how do we know it works? Lets install it!

The Visual Studio story

In my Visual Studio project, I delete “Feedjit” folder with all source files in it. That effectively uninstalls widget from solution. Here is how to install it from NuGet package we created:

1. Right click BlogEngine.NET project and select “Add Library Package Reference”. In the dialog box, click “Settings” in the lower left corner.

2. To add our “c:\packages” as local repository, fill in name and source and hit “ok”


From now on, you should be able to select that local feed and install any NuGet package that you have inside c:\packages folder. Here is what my local repository looks like:




Click “Install”, and Feedjit will be added to solution, just like that. We got all power of NuGet here, for example you can just as easily uninstall package:

uninstallUpdate and versioning all provided by NuGet, so if you happen to have multiple versions of your widget, extension or theme – you’ll just package it with new version number and you done. Pretty cool stuff. What could be more cool?

BlogEngine.NET gallery

Having local package repository is great. You could even submit your package to official NuGet feed and let people know about that wonderful extension you created, so they can install it from Visual Studio. But can we haz app store plz?

Yes we can! Please meet dnbegallery.org Ok, just to be clear – see that “beta” in the logo? It is wrong. It should really be “alpha” so if you crash site it is all your fault. But it should let you to register and upload your packages. Don’t’ tell anyone, just try it yourself and let us know what works and what doesn’t, we are very interested in your feedback. The process is very much identical to Orchard Gallery, except we don’t require email validation at this point so it is simpler a little.

Don’t get too excited just yet, we still missing a link when blogger can go to admin and click “install” button. Right now, it is just what it is – online repository to store and promote your packages. To install it, someone would have to download .nupkg file and then either rename/unzip/merge manually or add gallery feed to Visual Studio sources and get it from there. But that “Install” button is very high on to-do list.


Comments (14) -

  • Sanghino

    2/16/2011 9:47:10 AM |

    I&amp;amp;amp;#39;m Francesco, an italian developer, I try to open link in the post but at this moment dnbegallery do not work, this is the msg:

    Exception Details: System.Data.SqlServerCe.SqlCeException: There is a file sharing violation. A different process might be using the file. [ D:\Hosting\7173912\html\cms\App_Data\Sites\Default\Orchard.sdf ]

    at this line:

    Line 23:             builder.Add(T(&amp;amp;amp;quot;&amp;amp;amp;quot;), &amp;amp;amp;quot;2&amp;amp;amp;quot;, BuildMenu);

    Bye from Italy (Florence)

  • Janier Davila

    2/16/2011 11:33:58 AM |

    Being a Nuget and BlogEngine user, I got to love the idea! I went ahead and registered but the site crashed on me twice with a:

    There is a file sharing violation. A different process might be using the file. [ D:\Hosting\7173912\html\cms\App_Data\Sites\Default\Orchard.sdf ]

    Line 81:
    Line 82:         private PackageListViewModel BuildList(string searchTerm, string authorName, string packageType, string packageCategory, PagerParameters pagerParameters) {
    Line 83:             Pager pager = new Pager(_siteService.GetSiteSettings(), pagerParameters);
    Line 84:
    Line 85:             var packageTypeTerm = GetPackageTypeTerm(packageType);

    So yes, I guess it is not production ready just yet. Keep it up!

    • Brian Davis

      2/16/2011 12:35:47 PM |

      Having the same issue.

      There is a file sharing violation. A different process might be using the file. [ D:\Hosting\7173912\html\cms\App_Data\Sites\Default\Orchard.sdf ]

  • rtur.net

    2/16/2011 12:23:51 PM |

    Yes, this file sharing is killing us :( Presumably, this is due to our host (GoDaddy) having issue running SqlServer CE on its farm (http://orchard.codeplex.com/discussions/246199). Looking into way to upgrade to full Sql Server.
    This goes away if you hit refresh button in the browser, but very annoying.

    • Ben Amada

      2/16/2011 1:02:05 PM |

      Just confirming I&amp;amp;amp;#39;m seeing the same file sharing errors.  Nice initiative anyways.

  • rtur.net

    2/16/2011 2:03:39 PM |

    Ok, we are on SQL server now. Should not see that stupid file sharing violation any more.

    Welcome back Ben!

  • rtur.net

    2/16/2011 3:42:27 PM |

    And down again... looks like GoDaddy blocked connection to SQL server running outside their farm. Opened support ticket.

    • Brian Davis

      2/17/2011 5:31:58 PM |

      Getting this error when going to Widgets links:

      URL: http://dnbegallery.org/cms/Orchard.Gallery/Packages/ByCategory?categoryName=Administration

      Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

      Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

      Source Error:

      Line 125:                var shape = _orchardServices.ContentManager.BuildDisplay(contentItem, &amp;amp;amp;quot;Summary&amp;amp;amp;quot;);
      Line 126:                shape.AllowOwnerActions = false;
      Line 127:                if (_userPackageAuthorizer.AuthorizedToEditPackage(contentItem.As&amp;amp;amp;lt;PackagePart&amp;amp;amp;gt;().PackageID)) {
      Line 128:                    shape.AllowOwnerActions = true;
      Line 129:                }

      Source File: d:\hosting\7173912\html\cms\Modules\Orchard.Gallery\Controllers\PackagesController.cs    Line: 127

      • Brian Davis

        2/21/2011 9:53:58 PM |

        Seems to be working great now!

  • Daniel

    2/23/2011 6:08:35 PM |

    Great blog about blogengine.net, I&amp;amp;amp;#39;m getting more and more interested in trying it ,the more I read about it.

  • jitendra singh

    2/27/2011 6:07:23 AM |

    its great to hear all such stuff. I too started contributing to blogengine, very soon you will hear lot more from me.

  • Sunny

    3/10/2011 1:46:16 PM |

    Nice post, NuGet rocks!

  • blogEngineWall

    3/17/2011 9:09:59 PM |

    Its time for Nuget. Its been here since long time but couldnt used earlier.

    Nuget makes life easier. Nice post !!

  • gilbertos

    7/7/2011 4:52:30 PM |

    NuGet rocks <3
    thank you for this nice article !

Pingbacks and trackbacks (3)+

Comments are closed