Tuesday, February 22, 2011

How I NuGet - Creating a NuGet Package–Without a batch file

This is a follow-up to a previous post How I NuGet – Creating a NuGet Package where I used a batch file to create my NuGet package.

The batch file is not a necessary step in the process – it’s just a preference of mine.  However, after refactoring the process to use the NuGet native commands to include files, I’m leaning toward eliminating the batch step in my process.  Recall the following high-level outline of the steps used to create the NuGet package from the previous post:
  1. Download the NuGet Command Line tool
  2. Create a generic nuget nuspec file - the nuget manifest file
  3. Update the nuget manifest with project specific settings
  4. Create a batch file (.bat) file that will serve as the main entry point into the nuget package creation process
  5. Create the nuget package
  6. Submit and contribute the package to the NuGet Gallery
Eliminating step 4, creation of the batch file and updating step 3, Update the NuGet manifest settings to the following:

<?xml version="1.0"?>
<package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
        <authors>Dan Ryan</authors>
        <owners>Dan Ryan</owners>
        <description>UI Extensions to the MvcContrib Project - Themed Grid & Menu</description>
        <tags>MVC MVC3 ASP.NET MvcContrib</tags>
            <dependency id="MicrosoftWebMvc" version="2.0" />
            <dependency id="MvcContrib.Mvc3-ci" version="" />
        <file src="..\src\MvcContrib.Shp\MvcContrib.Shp\bin\Release\MvcContrib.Shp.dll" target="lib" />
        <file src="..\src\MvcContrib.Shp\Shp.Web\Scripts\jquery.mvccontrib*.*" target="content\Scripts" />
        <file src="..\src\MvcContrib.Shp\Shp.Web\Scripts\superfish.js" target="content\Scripts" />
        <file src="..\src\MvcContrib.Shp\Shp.Web\Scripts\*jquery.hoverIntent*" target="content\Scripts" />

The XML files element in the snippet above will include the child file elements in the NuGet package and place the respective file in the associated target (destination directory) of the NuGet package – the snippet above uses targets of lib and content.  You can read all above the files element and other NuGet file specifications here: .nuspec File Format

Again, this is an alternative (and recommended) way to create a NuGet package.  All the other steps in the high-level outline of steps (above) remains the same.

Thanks for reading…

No comments: