In this section, we’ll see the major changes in ASP.NET 5. The very first change is on the lines of Project system. Projects are now based on File System. So, all you need to do is add something to a project, say new source code file is just to place the file in the right directory. So, you can edit the source code file, save the file and the build just happens dynamically. Thanks to new Roslyn compiler which compiles the source code in memory which allows for faster build and faster refresh.
The project structure itself changed from previous versions. Also, one point to note while building application, we’ll be having two different options of choosing runtime. First is the full blown runtime as 4.5.1 or greater than that or the second option we can have cloud optimized runtime also called core CLR. Here, all the pieces like JIT Compiler, Garbage Collector are packaged and designed keeping high throughput and low memory consumption in mind. And now the application can have this cloud optimized environment embedded with the application which makes it easier to have true side by side version and by embedded, it means you can deploy the .NET Framework by copying the nuget package. So, the idea behind this cloud version of .NET runtime is; it should be platform independent which means it can also run on MAC and LINUX machine.
Another great fact about the new changes in ASP.NET 5 is the unification. So, now:
MVC 6 = ASP.NET MVC + WEB API
In MVC 6, WEB API is merged with MVC. This means we will now have one set of controller class, one set of attributes, model binders, etc. Also, it no longer relies on the namespace system.web
which means it is easy to self host and run the core CLR. Now, with these changes in place, it doesn’t mean that your existing projects won’t work in VS 2015; It will work as smooth as it was in earlier versions. Now, let's go ahead and start the demo. I already have RC version of VS 2015 installed on my 2ndry machine. Let's go ahead and create a new project.
Now, the below window is very much familiar to previous version. Here, I am interested in the new templates introduced. Hence, I am going to create a new project with ASP.NET 5 Website. This project will give me all the required components to run an app as shown below in the screen shot.
So, below shown window will be the new window for ASP.NET 5 project.
And when I run the same, it will produce the below output. Very traditional MVC APP.
One point to also note is that now folder organization in the file system and solution explorer is the same as you can see in the below screen shots.
This also means whatever changes I make in the file system under src folder, it will take effect in VS. Let’s create myImages folder in the file system with one image there. As soon as I added the image in the file system, it gets automatically synced with Solution Explorer.
Now, let's create one controller, say GreetController
but from the Notepad; this is just to prove the point that we don’t need to build the app to take the code changes effect.
Now, after saving the same when I refresh the browser, it will return the new controller’s output. So, this is called dynamic compilation.
Thanks for joining me for the first edition of ASP.NET 5. We’ll delve further in coming topics. Till then, stay tuned and happy coding!
CodeProject