A 30 Minute Look At ASP.NET vNext Tuesday, May 13, 2014

This week at TechEd, the ASP.NET team announced some pretty exciting updates on the way for ASP.NET.

Top Links

Blog Posts

Getting Involved

What Is It?

In case you haven't read up on it, I'll just quote from the ASP.NET site:

The next version of ASP.NET (“ASP.NET vNext”) has been re-designed from the ground up. The goal is to create a lean and composable .NET stack for building modern cloud-based apps. Here are some of the features of ASP.NET vNext: vNext includes new cloud-optimized versions of MVC, Web API, Web Pages, SignalR, and Entity Framework.

MVC, Web API, and Web Pages will be merged into one framework, called MVC 6. The new framework removes a lot of overlap between the existing MVC and Web API frameworks. It uses a common set of abstractions for routing, action selection, filters, model binding, and so on. You can use the framework to create both UI (HTML) and web APIs.

ASP.NET vNext apps can use a cloud-optimized subset of .NET vNext. This subset is factored for server and web workloads, has a smaller footprint than the full .NET vNext, and supports side-by-side deployment.

MVC 6 has no dependency on System.Web. The result is a leaner framework, with faster startup time and lower memory consumption.

vNext will support true side-by-side deployment. If your app uses the cloud-optimized subset of .NET vNext, you can bin deploy all of your dependencies, including the .NET vNext (cloud optimized) packages. That means you can update your app without affecting other applications on the same server.

vNext is host agnostic. You can host your app in IIS, or self-host in a custom process. (Web API 2 and SignalR 2 already support self-hosting; ASP.NET vNext brings this same capability to MVC.)

Dependency injection is built into the framework. Use your preferred IoC container to register dependencies.

vNext uses the Rosyln compiler to compile code dynamically. You will be able to edit a code file, refresh the browser, and see the changes without rebuilding the project.

vNext is open source and cross platform.

To me as a web developer, this means I get:

All the advantages of the .NET platform (performance, stability, security, comprehensive API), and

The development experience of C# and Visual Studio... with

The simplicity, portability, quick dev refresh cycle and flexibility of an interpreted web framework.

And I like the sound of that.

Source Code

All the source code and samples are published under a new ASP.NET organization on GitHub. There are lots of interesting repos to look at; here are some top ones to get started with:

This is the place to get started. The readme for this repo explains how to install and run the Hello World samples.

Ah, the Music Store. The team wanted some samples to validate and test vNext as they developed it, and this was one of them. I updated the source code to ASP.NET MVC 5 and threw it over the wall to them, and it seems to have held up. Cephas Lin has a Music Store walkthrough posted in the vNext content on the ASP.NET site, and it's pretty easy to follow along.

The BugTracker is a single page application using SignalR, Knockout.js and Web API. I'm pretty happy that they had a single page application as one of their validation cases from the beginning.

If you're feeling adventurous, this it the actual runtime. It includes things like the compilation system, SDK tools, and the native CLR hosts. (parental warning advisory if stumbling across some C++ gives you nightmares)

Quick Walkthrough

I promised I'd skip the detailed walkthrough, because you really should be looking at the "official" ones I've linked to above. My point here is not really guide you through them, but to give you a look at what the experience is like if you're not feeling up to doing it yourself. So let's see what I can get running in 30 minutes or so (until my next meeting). If you want to follow along, read the walkthroughs.

Important Notes Before We Get Started

I'm doing this on my dev machine. It runs side by side with my existing .NET and Visual Studio 2013 installs.

This looks a bit fiddly because we're doing this all from the commandline. Don't worry if that's not your bag - this will all be supported via Visual Studio. This is an early preview. But, it's good that this level of control is available. Note that I'm doing all of this without firing up Visual Studio or installing any other software.

You'll see the letter K pops up from time to time. This was internally called Project K before it was released. I have no idea if the k will go away now, but I kind of like it. So we've got kvm (k version manager), kre (k runtime engine), kpm (k package manager), and k (the actual bootstrapper to run our app).

The Home Repo samples

First, let's try out the ASP.NET vNext Home repo. I've already got this locally, but for the purposes of science I'll pretend that I don't. Since I'm just kicking the tires here, instead of cloning the repo I'll just download the zip to my desktop, unblock if necessary, and unzip it.

Here's what that gets me:

The next step in the readme tells me to execute kvmsetup.cmd, which tells me this:

And with that, we've got the version manager installed. Important: this is the version manager, not the runtime. We can install multiple versions of the runtime engine, and use kvm to select the active one for a project.

Next, the readme tells me to install a named version of the K Runtime Engine: kvm install 0.1-alpha-build-0421

Now we've got a runtime installed, so we can run some samples. The readme recommends running the console sample first, and I think that makes sense since it's an incredibly simple app that verifies things are installed. So I cd to samples\ConsoleApp and run kpm restore. This looks scary, but it's really fast, and it's a good thing. The idea is that instead of running on big, monolithic framework assemblies, ASP.NET vNext is grabbing a bunch of small, focused NuGet packages.

Now I run it with k run:

Like I said, not all that exciting. Just a quick verification check. Now that I know that's working, I'll quickly pop into one of the other sandbox samples, the HelloWeb one. Notice how simple the startup.cs file is (the official walkthrough explains it in detail).

Now I'll call kpm restore , just like before. This time kpm restore takes a bit longer, because there are more included packages (listed in project.json) and their dependencies.

And I'm ready to run it. This time, instead of k run, I'll call k web since it's a web app. If I forget and call k run, it reminds what's what:

Fine, k web it is. It tells me the server's started, but how do I view it? Well, the readme tells me it's at http://localhost:5001, but if I didn't know I could consult the commands section of project.json:

Simple enough. And browsing to that gives me a cool hello world page:

Nerd note: That page is shown because we've got app.UseWelcomePage() in startup.cs. There are no images or css in the project because everything's contained in the emitted HTML. It's actually really impressive - it's got embedded fonts, images as data:urls, CSS, and a minimized version of jQuery (for some nice animations), so it's a 287KB HTML payload... but since it's being served locally and you're not going to run this in production, not a problem.

Nerd smackdown: David Fowler reminded me that this welcome page has been in Katana for a while.

Music Store

Okay, now that I've got this stuff installed, let's see how fast I can get the Music Store sample running.

Step 1: Grab the zip from https://github.com/aspnet/MusicStore, verify it's not blocked, and unzip on desktop.

Step 2: Run kpm restore.

Step 3: Select the hosting opeion (Helios, SelfHost, CustomHost - explained here). In this case I'll stick with selfhost, so I run k web and browse to localhost:5002:

Yippee!

Again, the point is that it's pretty quick and painless to get started and play with the samples; just follow the walkthroughs. If you're used to Node or Rails a lot of these steps should seem pretty familiar. If you're not and this freaks you out, don't be freaked out... this will all work smoothly from within Visual Studio in the release version. This is a preview. Take a look! Have Fun! Let us know what you think!

Videos

The best way to get up to speed is by watching the videos I mentioned earlier.