Nuget Package Errors DNX451 & 5.0

We've been early adopters of Asp.Net 5.0 and MVC6 by using the framework for an A/B test that we are performing.

One thing that has been most apparent is the impact of nuget packages in the application and more specifically the nightmare that can unfurl when with nuget packages can't be found and and the project won't build.

The key thing that took me a while to figure out is that using the command line along side the Visual Studio tools is imperative to getting the application to build correctly against the correct version of the framework.

In the early stages of the framework when the Beta releases are being released against a consistent release cycle it's important to know the few key commands to get you through the pain that can occur when you aren't aware of whats going on with your packages.

What we've found is that right clicking on the project and selecting "restore packages" can sometimes work but many times just fails.

In the instances where the application won't build, there are a few steps we can take to get the application to work, this is really important in the case where you might have upgraded your application to the latest beta but the rest of the team you work with haven't.

If you haven't set up the visual studio command line you can find the details on how to do this here;

I always start by navigating my powershell location to the project in question.

The first step I get the guys to do when something won't build is:

dnvm upgrade - this will upgrade the dotnet version manager to include all of the latest versions of the framework.

Once we have all the versions we should choose the version that we wan't to use our project by executing:

dnvm use --version 1.0.0-beta8 (with the version being the version you wish to use against your project).

Performing dnvm list should show the list of current projects and you should see a star next to the project you've set for usage.

Once we have selected the version that we want to use, we need to make sure that the packages in our application are correct and matching the version of the runtime that we are using.

In order for this to work we need to ensure that all of our nuget package locations are in check, the locations I have setup in my global nuget config are as follows:

    <add key="" value="" protocolVersion="3" />
    <add key="" value="" />
    <add key="AspNetVNext" value="" />
    <add key="Roslyn" value="" />
    <add key="DotNet" value="" />

You can find the global nuget file at: C:\Users\<your account>\AppData\Roaming\NuGet.

The final step to run is the restoration of the nuget packages by running the following command in the project directory location:

dnu restore --no-cache

This should restore all of the packages to their correct state with the correct versions of the packages for the currently selected runtime. from here we can navigate back to Visual Studio, rebuild our project and all of our dependency errors should disappear!