Quantcast
Channel: ASP.NET Core – Software Engineering
Viewing all articles
Browse latest Browse all 273

ASP.NET Core 1.0 updating to beta8 from older beta versions

$
0
0

This post just explains some of the things you need to do when updating to ASP.NET Core 1.0 beta8 from older versions. I have updated some existing ASP.NET Core 1.0 example projects to beta8.

The first thing you have to do is to update your dnvm, dnu and your dnx. This is the same as always. Documentation can be found here for windows, mac and linux. You must also update your Visual Studio Web tools because the new httpplatformhandler needs to be installed in the IIS Express. This also needs to be updated in the IIS depending how you deploy your projects.

Updating your MVC 6 project

I usually update the project.json file first. Here is an example of some of the beta8 references which are usually required in a MVC 6 project. The Microsoft.AspNet.IISPlatformHandler is a new dependency. The commands also need to be updated. Now the web command uses kestrel.

    "dependencies": {
        "Microsoft.AspNet.Diagnostics": "1.0.0-beta8",
        "Microsoft.AspNet.IISPlatformHandler": "1.0.0-beta8",
        "Microsoft.AspNet.Mvc": "6.0.0-beta8",
        "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta8",
        "Microsoft.AspNet.Server.Kestrel": "1.0.0-beta8",
        "Microsoft.AspNet.StaticFiles": "1.0.0-beta8",
        "Microsoft.Framework.Logging": "1.0.0-beta8",
        "Microsoft.Framework.Logging.Console": "1.0.0-beta8",
        "Microsoft.Framework.Logging.Debug": "1.0.0-beta8",
        "NEST": "1.7.0",
        "Microsoft.Net.Http": "2.2.29",
        "Microsoft.AspNet.SignalR.Server": "3.0.0-beta8-15656",
        "NEST.Watcher": "1.0.0-beta2"
    },
    "commands": {
        "web": "Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:17202"
    },

Once everything is restored, you must replace your web.config file inside the wwwroot folder in your MVC 6 application. Replace it with the following:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
	<system.webServer>
		<handlers>
			<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
		</handlers>
		<httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" forwardWindowsAuthToken="false" startupTimeLimit="3600" />
	</system.webServer>
</configuration>

The Startup class requires some changes as well. The main change is that the “app.UseIISPlatformHandler();” middleware is now required. The configuration and the UseExceptionHandler have also been updated/added. Here’s an example of a beta8 Startup class. You could also use yoeman to get a beta8 template.

using AspNet5Watcher.Configurations;
using AspNet5Watcher.SearchEngine;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.Dnx.Runtime;
using Microsoft.Framework.Configuration;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging;

namespace AspNet5Watcher
{
    public class Startup
    {
        public IConfigurationRoot Configuration { get; set; }

        public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(appEnv.ApplicationBasePath)
                .AddJsonFile("config.json");
            Configuration = builder.Build();
        }
 
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<ApplicationConfiguration>(Configuration.GetSection("ApplicationConfiguration"));

            services.AddMvc();
            services.AddSignalR(options =>
            {
                options.Hubs.EnableDetailedErrors = true;
            });

            services.AddScoped<SearchRepository, SearchRepository>();
        }

        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.MinimumLevel = LogLevel.Information;
            loggerFactory.AddConsole();
            loggerFactory.AddDebug();

            app.UseIISPlatformHandler();

            app.UseExceptionHandler("/Home/Error");

            app.UseStaticFiles();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
            app.UseSignalR();
        }
    }
}

Then of course your code will require some changes. For example filters have been moved to a new namespace, or the configuration options uses the Value property not like before, or Entity Framework Entity class has replaced the Key property with HasKey. There are lots of breaking changing in this version, but it is a beta version. Here’s a list of breaking changes.

I also had an issue with ports and the kestrel server.

https://github.com/aspnet/Home/issues/993

Links

http://blogs.msdn.com/b/webdev/archive/2015/10/15/announcing-availability-of-asp-net-5-beta8.aspx

https://github.com/aspnet/Home/releases/tag/v1.0.0-beta8

http://www.iis.net/downloads/microsoft/httpplatformhandler

https://azure.microsoft.com/en-us/blog/announcing-the-release-of-the-httpplatformhandler-module-for-iis-8/



Viewing all articles
Browse latest Browse all 273