March, 2015 browsing by month


Simplified process of creating and publishing nuget package to local host

Monday, March 9th, 2015

The simplified steps to pack and publish nuget packages to local host:

Add NuGet executable path to system variables:

  • Opened Properties page of Computer and click on Advanced System Settings and select Environment Variables
  • Highlight the Path under System Variables and click on Edit
  • Located the folder where the Nuget.exe is located, in this case, C:\Program Files (x86)\NuGet\Visual Studio 2012 and add this path to the Variable value – separated by semi-colon;
  • Need to re-start the computer in order for this to take effect.

 Package the libraries that are to be published to the server:

    • Launch the Developer Command Prompt for VS2012 and browse to the folder where the project file is located; in this case G:\Development\Tryout\NugetServer\Demo.Nuget.Lib>
    • Run command nuget spec to create the .nuspec file first:
      G:\Development\Tryout\NugetServer\Demo.Nuget.Lib>nuget spec -f Demo.Nuget.Lib.cs
      Created 'Demo.Nuget.Lib.nuspec' successfully.

      use -f to force overwrite if the .nuspec file already exists.

    • Open the .nuspec file and remove these entries from the file for now:
      <tags>Tag1 Tag2</tags>

      and make sure also change the text of releaseNotes to something other than the default; if you don’t to this, you will get an annoying warning message asking you to change.

    • Then run nuget pack command:
      G:\Development\Tryout\NugetServer\Demo.Nuget.Lib>nuget pack Demo.Nuget.Lib.cspro
      j -includeReferencedProjects
      Attempting to build package from 'Demo.Nuget.Lib.csproj'.
      Packing files from 'G:\Development\Tryout\NugetServer\Demo.Nuget.Lib\bin\Debug'.
      Using 'Demo.Nuget.Lib.nuspec' for metadata.
      Successfully created package 'G:\Development\Tryout\NugetServer\Demo.Nuget.Lib\D

Publish the package to local server:

      • Finally, do a push to publish to localhost:
        G:\Development\Tryout\NugetServer\Demo.Nuget.Lib>nuget push Demo.Nuget.Lib.1.0.0
        .2.nupkg -s http://localhost:{portnumber if not default 80, for example 8090 was what I used} {api key this has to be obtained from}
        Pushing Demo.Nuget.Lib to 'http://localhost:8099'...
        Your package was pushed.
      • The local server was previously setup by following this article at

Consume the packages from the local Nuget Server:

Now that the package are published to the local server, here are the steps to consume it from inside a Visual Studio 2012 solution:

  • Added a Console project “Demo.Nuget.Consumer”
  • Go to Tools->Nuget Package Manager->Manager Nuget Packages for Solution
  • Click on Setting on the lower left corner and select Package Sources under the Package Manager from the Options pane on the left; click on the “+” sign to add a new package source
  • Type in the Source text box the local Nuget server url that was used in the publishing process, and add nuget at the end, for example in this case :http://localhost:8099/nuget
  • Once the Package source is added, then all the .nupkg files in the Packages folder on the server will be displayed on the “Manage NuGet Packages” screen and ready to be installed to the solution.
  • To make more packed assemblies to be available to the source, just simply copy the desired .nupkg file(s) to the Packages folder on the server and they will automatically show up for your solution.