Migration from ASP.NET Beta 4 to Beta 5

ASP.NET beta 5 was released on June 30th. See this blog post from Microsoft for details. I also recommend this video of the ASP.NET community standup from the day of the beta 5 release it has a lot of great information on the release and way forward for ASP.NET 5. This post is going to cover a migration of my contacts application from beta 4 to beta 5.

To start upgrade dnvm by opening a command prompt and running the following command.

dnvm update-self

After that is complete use dnvm to get beta 5 by running the following.

dnvm upgrade

The rest of the migration was performed from Visual Studio. Next up is an update to global.json to change the version from beta4 to beta5.

{
    "projects": [ "src", "test" ],
    "sdk": {
        "version": "1.0.0-beta5"
    }
}

In project.json the dependencies section needs values beta4 updated to beta5.

  "dependencies": {
    "EntityFramework.SqlServer": "7.0.0-beta5",
    "EntityFramework.Commands": "7.0.0-beta5",
    "Microsoft.AspNet.Mvc": "6.0.0-beta5",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta5",
    "Microsoft.AspNet.Authentication.Cookies": "1.0.0-beta5",
    "Microsoft.AspNet.Authentication.Facebook": "1.0.0-beta5",
    "Microsoft.AspNet.Authentication.Google": "1.0.0-beta5",
    "Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-beta5",
    "Microsoft.AspNet.Authentication.Twitter": "1.0.0-beta5",
    "Microsoft.AspNet.Diagnostics": "1.0.0-beta5",
    "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta5",
    "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta5",
    "Microsoft.AspNet.Server.IIS": "1.0.0-beta5",
    "Microsoft.AspNet.Server.WebListener": "1.0.0-beta5",
    "Microsoft.AspNet.StaticFiles": "1.0.0-beta5",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-beta5",
    "Microsoft.Framework.CodeGenerators.Mvc": "1.0.0-beta5",
    "Microsoft.Framework.Configuration.Json": "1.0.0-beta5",
    "Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta5",
    "Microsoft.Framework.Logging": "1.0.0-beta5",
    "Microsoft.Framework.Logging.Console": "1.0.0-beta5",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta5"
  }

One big thing here to note is that Microsoft.Framework.ConfigurationModel and all its children have been renamed to Microsof.Framework.Configuration. For example Microsoft.Framework.ConfigurationModel.Json is now Microsoft.Framework.Configuration.Json.

In the Views folder _GlobalImport.cshtml needs to be renamed to _ViewImports.cshtml.

Entity framework migrations had some issues as well, but I decided to just delete the existing migrations and start from scratch since the database contains a minimal amount of data.

The last set of changes are in Startup.cs. First up is a using change for the ConfigurationModel to Configuration rename.

Before:
using Microsoft.Framework.ConfigurationModel;

After:
using Microsoft.Framework.Configuration;

Next up is the Startup function. Here a builder has been added which is then used to create the actual configuration. Also note the added function parameter for IApplicationEnviroment which is used to get the application path for use by the configuration builder.

Before:
public Startup(IHostingEnvironment env)
{
    // Setup configuration sources.
    var configuration = new Configuration()
        .AddJsonFile("config.json")
        .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);

    if (env.IsEnvironment("Development"))
    {
        // This reads the configuration keys from the secret store.
        configuration.AddUserSecrets();
    }
    configuration.AddEnvironmentVariables();
    Configuration = configuration;
}

After:
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
    // Setup configuration sources.
    var configurationBuilder = new ConfigurationBuilder(appEnv.ApplicationBasePath)
        .AddJsonFile("config.json")
        .AddJsonFile($"config.{env.EnvironmentName}.json", true);

    if (env.IsEnvironment("Development"))
    {
        // This reads the configuration keys from the secret store.
        configurationBuilder.AddUserSecrets();
    }

    configurationBuilder.AddEnvironmentVariables();
    Configuration = configurationBuilder.Build();
    
}

In the ConfigureServices function Configuration.GetSubKey has been replaced by Configuration.GetConfigurationSection.

Before:
services.Configure<AppSettings>(Configuration.GetSubKey("AppSettings"));

After:
services.Configure<AppSettings>(Configuration.GetConfigurationSection("AppSettings"));

The last change was to remove app.UseBrowserLink. I am not thrilled with having to remove the use of browser link but it is throwing a System.TypeLoadException. I am going to keep looking for this issue but with UseBrowserLink commented out everything else works fine. If anyone else has this issue and finds a fix please leave a comment on how it was fixed.

If your application is still having trouble check out this page which contains a list of breaking changes from beta 4 to beta 5.

2 thoughts on “Migration from ASP.NET Beta 4 to Beta 5”

  1. Marcos Paulo Honorato da Silva

    I’m using the Microsoft.AspNet.Identity.EntityFramework v3.0.0-beta4, however, I’m not getting a solution to customize the AspNetUserClaims table.

    I can add attributes to AspNetUser and AspNetRoles tables, as in my code below.

    public class ApplicationUser : IdentityUser
    {
    public string Name { get; set; }
    }

    public class ApplicationRole : IdentityRole
    {
    public int AppId { get; set; }
    public string Description { get; set; }
    // Navigation Properties
    public virtual App App { get; set; }
    }

    public class ApplicationDbContext : IdentityDbContext
    {
    private static bool _created;
    public virtual DbSet App { get; set; }
    public ApplicationDbContext()
    {
    if (!_created)
    {
    Database.AsRelational().ApplyMigrations();
    _created = true;
    }
    }

    protected override void OnModelCreating(ModelBuilder builder)
    {
    base.OnModelCreating(builder);
    }
    }

    1. Marcos did you create a new migration from your changes? Based on the code you posted if you had a migration it should have been applied when an instance of ApplicationDbConext was created.

      This covers adding a new migration if that is the step you are missing.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.