Creating a Private NuGet repository and Creating Packages (Part 2)

Posted by & filed under Microsoft, NuGet, Visual Studio.

For creating a Private NuGet Repository – See Part 1

Creating the Packages

To create the packages themselves, you’ll need the NuGet Command Line package installed on your system (this can be installed using NuGet).

Next go to the command line and change to your project’s directory. Issue the following command…

Nuget spec MyProject.sln

… where MyProject.sln is the name of you solution file.

A nuspec file manifest should be created and look something like the following…

The dollar placeholders are populated automatically when the package is created from the information given to the assemblies. You can replace these with static fields if you would like. From here, you can simply call the following command to generate a nuget package (a .nupkg file)…

nuget pack MyProject.sln.nuspec

.. however, this tends to generate a package with all of your assemblies and content, along with any third party dependencies. Not what you’d normally want!

The way I now generate these packages is to list the files and dependencies in the nuspec file. This overrides everything and ONLY includes those files.

At this point it’s probably worth explaining the directories listed as the target attribute in the above XML. There are three main folders that NuGet uses in it’s package structure – lib, content and tools.

Content contains any content you’d like placed in the root of a project that implements your package.

Tools contains powershell script files to be run when the package is installed for the first time, every time it is installed and when it is uninstalled. I’m not going to go into too much detail about the powershell scripts, but Init.ps1 will run the first time a package is run in a given solution, Install.ps1 will run every time a package is installed on a project within a solution and Uninstall.ps1 will run when a package is uninstalled. For more info on powershell within NuGet packages see

Lib contains folders with specific framework versions with dlls that will be added as a reference for projects implementing your package. Common framework versions are listed below

Tool Target Notes
.NET 4.0 net40 Just using ’40’ also works.
.NET 4.0 Client Profile net40-client
.NET 4.0 Full Profile net40-full Requires full .NET profile
.NET 4.0 Compact Framework net40-cf net40-compactframework also works.
Silverlight 4.0 sl4
Windows Phone 7.0 sl3-wp
Windows Phone 7.1 (Mango) sl4-windowsphone71

Now run the nuget pack command above and the nuget package will create a file containing only the files you specify. Give the nupkg file a .zip extension and open it and you can check out what’s been created.

I hope this has been helpful. Watch this space for more .NET info.

UPDATE: “Failed to download package correctly. The contents of the package could not be verified”

We’ve run into the issue where NuGet plugin for Visual Studio reports “Failed to download package correctly. The contents of the package could not be verified” whilst updating a package. There’s a few comments on CodePlex, and I’ve come to the conclusion that this is because Nuget is requesting a version of the package, which has been cached by the client. Nuget performs some kind of hash check including the version number that it’s expecting to receive and the actual package it got, along with a hash value in the package.

To solve this issue, click on the Nuget server application in IIS and click on HTTP response headers. Select the option for “Set common headers” (in the side bar) and check “Expire Web Content” along with the “Immediately” radio button. This sets HTTP headers to tell the clients not to cache the packages.


Creating a Private NuGet repository and Creating Packages (Part 1)

Posted by & filed under Microsoft, NuGet, Visual Studio.

Most companies have some kind of “Common” framework that houses common pieces of functionality and encapsulates how things such as logging and caching are done at that particular organisations. This is fine if compiled into one or two assemblies, but can be much more troubling to integrate into new projects if other resources are required such as JavaScript files and images.

One solution is to publish packages to NuGet, allowing projects to download and implement the package. Assemblies are automatically referenced (using the correct assemblies for the framework version used) and content is placed in the correct directory structure. Powershell scripts can even be used and executed on first install, update and uninstall, and developers are notified when they open a project where a package has an update available. However, if this is bespoke code it’s probably not desirable to publish the package to a public NuGet repository. This is where a private NuGet repository comes in useful, and it’s surprisingly easy to implement.

Creating the NuGet Server

Open up Visual Studio and create a new ASP.NET Empty Web Application Project. Assuming you have NuGet package manager installed, right click on the project and select Add Library Package Reference. Search for NuGet.Server and click install.

You’ll see a number of dependencies installed such as NuGet.Core, Ninject and Elmah (you’ll need to accept the Ninject agreement), and once installed you’ll see a few new folders in your project.

The packages folder is where you place the packages you’d like to make available to people who can see your NuGet Server. That’s it! Hit F5 and you’ll see a webpage with info about the NuGet repository.

Publish the project on a web server somewhere within your organisation, taking note of the URL displayed within the page (once published).

Configuring NuGet Package Manager

Now head back to Visual Studio and click Tools > Options. Scroll down to package manager and enter a name and the URL from your repository.

When adding a new library package, your new server should show up in NuGet Package Manager.

All done! I’ll be blogging in the next few days about creating your nupkg files (including the package manifect or nuspec file) to place into the packages directory to allow projects to download and implement.

ASP.NET 4.5, Visual Studio 2011, MVC4 announcements

Posted by & filed under .NET 4.5, Development, Microsoft, MVC4, Visual Studio 11.

Some interesting announcements were made last week during BUILD2011, and here’s some of the things I’m most excited about.

Changes in the way products are released

Scott Hanselman comments on his blog:

“It’s also worth noting that while there is a bunch of stuff in the next version of Visual Studio, there’s an equally compelling amount of stuff being released from the Azure/Web Team on NuGet.”

It’s great that’s now so easy to add new packages to an existing project so easily. The days of searching for dll’s, copy and pasting config sections around is over. This accommodates more granular releases for smaller pieces of functionality, and as Scott mentions, levels the playing field with other open source packages. Also Nuget is awesome, and I’ll be blogging later on creating your own read-only Nuget repository (useful for Enterprise level distribution of “Common” assemblies and dependencies.

MVC4 and Web Pages 2

Support for Mobile Views (something Scott Hanselman had been working on) are part of MVC4, along with new HTML5 templates and new mobile JQuery templates. Web Pages 2 seems quite interesting – a new lightweight framework for data-driven websites where the View and the Controller live in the same file. This seems to be pushed as part of WebMatrix (Microsoft’s lighter version of VS for developing with a number of open source frameworks).

Backwards Compatibility for Projects and Solutions (finally!)

I’ve always tried the latest version of Visual Studio soon after the developer preview is released, and it’s always seemed pretty limiting that you can’t just open an older project without having to convert it first. Whilst this limitation can be accepted during the previews and betas (as many organisations would frown upon using these for production code), once the RTM release is out it’s often months before everyone on your team has upgraded and the projects and solutions can be converted and checked in.

Finally Microsoft has listened! VS11 will have the ability to open and save projects and solutions without the need to convert. 🙂

Asyncronous Tasks and the “Await” Keyword

I’d been given a sneak preview of this at the Guathon earlier in the year, as demonstrated by Steve Sanderson. The new await keyword allows .NET to do all the hard work when using long running pieces of code, without having to code event handlers etc. See what I mean with the code below…

private async
Task ScrapeHtmlPage(object caller, EventArgs e)
    WebClient wc = new WebClient();
    var result = await wc.DownloadStringTaskAsync("");
    // Do something with the result

Easy huh? The framework will finish calling the rest of your code without blocking the thread, meaning you can handle more requests, quicker.


I’ve often looked at google’s PageSpeed tools and tried to improve the speed of my sites. One trick I’ve used is an http handler to bundle and minify the css and javascript into 2 compostite files (as this cuts down on HTTP requests).

.NET 4.5 gives you this functionality built right into the Routing Engine. For example, to include all of the js files in the scripts directory into one minified file, simply add the following to your HTML source…

<script src="scripts/js"></script>

Similarly, to include all of the css files in the Styles directory…

<link href="styles/css" rel="stylesheet" />

In Summary

Other features are being drip fed on Scott Guthrie’s blog, including HTML Editor Support for Smart Tasks and Event Handler Generation, Strongly Typed Data Controls, Model Binding Part 1: Selecting Data and Model Binding Part 2: Filtering Data.

The Visual Studio 11 Developer Preview can be found here.

There’s some fantastic developments coming from Microsoft at the moment to make a developer’s life easier and more thorough and I’m excited to see what’s coming next.

RoundCube Mail – Configuring LDAP with Windows AD

Posted by & filed under Active Directory.

Took me a while to figure this out today, so I’m posting in the hope that this helps someone out.

Below is the config for Roundcube Mail (which is wicked by the way) within One of the important things here was that without an OU, the search returned no results if left with the default LDAP port of 389. To search the whole organisation (without an OU) you need to change to the Global Catalogue port for Active Directory of 3268.

Hope this helps someone!

$rcmail_config['ldap_public']['MyLDAPAddressBook'] = array(
'name' => 'MyLDAPAddressBook',
'hosts' => array(''),
'port' => 3268, // IMPORTANT!! - Change this from default to Global Catalogue Port
'use_tls'=> false,
'user_specific' => true,
'base_dn'=> DC=MYDOMAIN,DC=COM',
'bind_dn' => '[email protected]',
'bind_pass'     => 'myLDAPPassword',
'writable'=> false, // Indicates if we can write to the LDAP directory or not.
'search_fields' => array('mail', 'cn'),
'name_field' => 'cn', // this field represents the contact's name
'firstname_field' => 'givenName', // this field represents the contact's first name
'surname_field' => 'sn', // this field represents the contact's last name
'email_field' => 'mail', // this field represents the contact's e-mail
'scope' => 'sub', // search mode: sub|base|list
'filter' => '(&(mail=*)(!(msExchHideFromAddressLists=TRUE)))' , // all mail, except the exchange hidden
'sort' => 'cn', // The field to sort the listing by.
'fuzzy_search' => TRUE); // server allows wildcard search