A 30 Minute Look At ASP.NET vNext
This week at TechEd, the ASP.NET team announced some pretty exciting updates on the way for ASP.NET.
Top Links
Blog Posts
- ASP.NET vNext: the future of .NET on the Server (.NET Web Development and Tools Blog)
- Introducing ASP.NET vNext (Scott Hanselman)
- ASP.NET vNext (David Fowler)
- The Next Generation of .NET – ASP.NET vNext (.NET Team Blog)
ASP.NET team session videos from TechEd
- INTRODUCING: The Future of .NET on the Server (Scott Hunter and Scott Hanselman)
- Channel 9 Live: ASP.NET Developer Q&A (Scott Hunter and Scott Hanselman)
- DEEP DIVE: The Future of .NET on the Server (David Fowler and Scott Hanselman)
ASP.NET site content
- Getting Started with ASP.NET vNext (Mike Wasson)
- MVC Music Store Sample Application for ASP.NET vNext (Cephas Lin)
- BugTracker Sample Application for ASP.NET vNext (Erik Reitan)
Getting Involved
- ASP.NET vNext Discussion Forum
- ASP.NET vNext chat on JabbR
- ASP.NET vNext Home repository on GitHub - The place to get started with the code
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:
Home repository
This is the place to get started. The readme for this repo explains how to install and run the Hello World samples.
Music Store sample
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.
BugTracker sample
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.
KRuntime
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:
C:\Users\Jon\Desktop\Home-master\Home-master>dir Volume in drive C has no label. Volume Serial Number is 5E2E-AE5E Directory of C:\Users\Jon\Desktop\Home-master\Home-master 05/13/2014 02:29 PM <DIR> . 05/13/2014 02:29 PM <DIR> .. 05/13/2014 01:51 PM 851 .gitattributes 05/13/2014 01:51 PM 245 .gitignore 05/13/2014 01:51 PM 1,513 CONTRIBUTING.md 05/13/2014 01:51 PM 356 kvm.cmd 05/13/2014 01:51 PM 17,278 kvm.ps1 05/13/2014 01:51 PM 28 kvmsetup.cmd 05/13/2014 01:51 PM 592 LICENSE.txt 05/13/2014 01:51 PM 481 NuGet.Config 05/13/2014 01:51 PM 6,390 README.md 05/13/2014 02:29 PM <DIR> samples 9 File(s) 27,734 bytes 3 Dir(s) 11,363,086,336 bytes free
The next step in the readme tells me to execute kvmsetup.cmd, which tells me this:
Copying file C:\Users\Jon\.kre\bin\kvm.ps1 Copying file C:\Users\Jon\.kre\bin\kvm.cmd Adding C:\Users\Jon\.kre\bin to process PATH Adding C:\Users\Jon\.kre\bin to user PATH Adding C:\Program Files\KRE;%USERPROFILE%\.kre to process KRE_HOME Adding C:\Program Files\KRE;%USERPROFILE%\.kre to machine KRE_HOME Press any key to continue ...
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
C:\Users\Jon\Desktop\Home-master\Home-master>kvm install 0.1-alpha-build-0421 Downloading KRE-svr50-x86.0.1-alpha-build-0421 from https://www.myget.org/F/aspnetvnext/api/v2/ Installing to C:\Users\Jon\.kre\packages\KRE-svr50-x86.0.1-alpha-build-0421 Adding C:\Users\Jon\.kre\packages\KRE-svr50-x86.0.1-alpha-build-0421\bin to process PATH
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.
C:\Users\Jon\Desktop\Home-master\Home-master>cd samples\ConsoleApp C:\Users\Jon\Desktop\Home-master\Home-master\samples\ConsoleApp>kpm restore C:\Users\Jon\Desktop\Home-master\Home-master\samples\ConsoleApp>CALL "C:\Users\Jon\.kre\packages\KRE-svr50-x86.0.1-alpha-build-0421\bin\KLR.cmd" --lib "C:\Users\Jon\.kre\packages\KRE-svr50-x86.0.1-alpha-build-0421\bin\;C:\Users\Jon\.kre\packages\KRE-svr50-x86.0.1-alpha-build-0421\bin\lib\Microsoft.Framework.PackageManager" "Microsoft.Framework.PackageManager" restore Restoring packages for C:\Users\Jon\Desktop\Home-master\Home-master\samples\ConsoleApp\project.json Attempting to resolve dependency ConsoleApp >= 1.0.0 Attempting to resolve dependency System.Console >= 4.0.0.0 GET https://www.myget.org/F/aspnetvnext/FindPackagesById()?Id='System.Console' GET https://nuget.org/api/v2/FindPackagesById()?Id='System.Console' Attempting to resolve dependency mscorlib >= Attempting to resolve dependency System >= Attempting to resolve dependency System.Core >= Attempting to resolve dependency Microsoft.CSharp >= Attempting to resolve dependency ConsoleApp >= 1.0.0 Attempting to resolve dependency System.Console >= 4.0.0.0 OK https://nuget.org/api/v2/FindPackagesById()?Id='System.Console' 931ms OK https://www.myget.org/F/aspnetvnext/FindPackagesById()?Id='System.Console' 972ms GET https://www.myget.org/F/aspnetvnext/api/v2/package/System.Console/4.0.0.0 OK https://www.myget.org/F/aspnetvnext/api/v2/package/System.Console/4.0.0.0 1696ms Attempting to resolve dependency System.IO >= 4.0.0.0 GET https://www.myget.org/F/aspnetvnext/FindPackagesById()?Id='System.IO' GET https://nuget.org/api/v2/FindPackagesById()?Id='System.IO' Attempting to resolve dependency System.Runtime >= 4.0.0.0 GET https://www.myget.org/F/aspnetvnext/FindPackagesById()?Id='System.Runtime' GET https://nuget.org/api/v2/FindPackagesById()?Id='System.Runtime' OK https://nuget.org/api/v2/FindPackagesById()?Id='System.Runtime' 659ms OK https://www.myget.org/F/aspnetvnext/FindPackagesById()?Id='System.IO' 838ms OK https://www.myget.org/F/aspnetvnext/FindPackagesById()?Id='System.Runtime' 841ms GET https://www.myget.org/F/aspnetvnext/api/v2/package/System.Runtime/4.0.20.0 OK https://nuget.org/api/v2/FindPackagesById()?Id='System.IO' 954ms GET https://www.myget.org/F/aspnetvnext/api/v2/package/System.IO/4.0.0.0 OK https://www.myget.org/F/aspnetvnext/api/v2/package/System.IO/4.0.0.0 1779ms Attempting to resolve dependency System.Text.Encoding >= 4.0.0.0 GET https://www.myget.org/F/aspnetvnext/FindPackagesById()?Id='System.Text.Encoding' GET https://nuget.org/api/v2/FindPackagesById()?Id='System.Text.Encoding' Attempting to resolve dependency System.Threading.Tasks >= 4.0.0.0 GET https://www.myget.org/F/aspnetvnext/FindPackagesById()?Id='System.Threading.Tasks' GET https://nuget.org/api/v2/FindPackagesById()?Id='System.Threading.Tasks' OK https://www.myget.org/F/aspnetvnext/api/v2/package/System.Runtime/4.0.20.0 1919ms OK https://nuget.org/api/v2/FindPackagesById()?Id='System.Text.Encoding' 746ms OK https://www.myget.org/F/aspnetvnext/FindPackagesById()?Id='System.Text.Encoding' 837ms GET https://www.myget.org/F/aspnetvnext/api/v2/package/System.Text.Encoding/4.0.10.0 OK https://www.myget.org/F/aspnetvnext/FindPackagesById()?Id='System.Threading.Tasks' 843ms OK https://nuget.org/api/v2/FindPackagesById()?Id='System.Threading.Tasks' 1051ms GET https://www.myget.org/F/aspnetvnext/api/v2/package/System.Threading.Tasks/4.0.0.0 OK https://www.myget.org/F/aspnetvnext/api/v2/package/System.Text.Encoding/4.0.10.0 1356ms OK https://www.myget.org/F/aspnetvnext/api/v2/package/System.Threading.Tasks/4.0.0.0 1721ms Resolving complete, 8357ms elapsed Installing System.Console 4.0.0.0 Installing System.Runtime 4.0.20.0 Installing System.IO 4.0.0.0 Installing System.Text.Encoding 4.0.10.0 Installing System.Threading.Tasks 4.0.0.0 Restore complete, 8495ms elapsed
Now I run it with k run:
C:\Users\Jon\Desktop\Home-master\Home-master\samples\ConsoleApp>k run Hello World C:\Users\Jon\Desktop\Home-master\Home-master\samples\ConsoleApp>
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).
C:\Users\Jon\Desktop\Home-master\Home-master\samples\HelloWeb>dir Volume in drive C has no label. Volume Serial Number is 5E2E-AE5E Directory of C:\Users\Jon\Desktop\Home-master\Home-master\samples\HelloWeb 05/13/2014 02:29 PM <DIR> . 05/13/2014 02:29 PM <DIR> .. 05/13/2014 01:51 PM 310,647 image.jpg 05/13/2014 01:51 PM 506 project.json 05/13/2014 01:51 PM 227 Startup.cs 3 File(s) 311,380 bytes 2 Dir(s) 11,368,951,808 bytes free C:\Users\Jon\Desktop\Home-master\Home-master\samples\HelloWeb>copy startup.cs con using Microsoft.AspNet.Builder; namespace KWebStartup { public class Startup { public void Configure(IBuilder app) { app.UseStaticFiles(); app.UseWelcomePage(); } } } 1 file(s) copied. C:\Users\Jon\Desktop\Home-master\Home-master\samples\HelloWeb>
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:
C:\Users\Jon\Desktop\Home-master\Home-master\samples\HelloWeb>k run 'HelloWeb' does not contain a static 'Main' method suitable for an entry point
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:
"commands": { "web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001" }
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.