A First Look at Installing ASP.NET 5, Part 1: Windows

This is part 1 of a 3 part series exploring ASP.NET 5 running on Windows, Mac OSX and Linux.

By now, .NET developers who don’t live in caves are aware that the newest version of ASP.NET, in addition to being open source and in general very different from previous iterations, is designed to run on multiple platforms, allowing us to finally start coding in C# on Macs and Linux machines. They are courageously helping us “blow out some Windows” so to speak. 

There are already a number of tutorials and resources online for how get started with ASP.NET 5 on a Mac or a Linux box, but since the framework is still under development and is constantly changing, I thought it would be useful to go through the process, see if I ran into any issues not highlighted in Microsoft’s current tutorials and “Getting Started” resources, and generally get a feel for how difficult it would be.

I find that most developers (myself included) spend far more time than they think they will installing and configuring new frameworks, tools, and environments than they think they will going in the door. It shouldn’t take three days to get that shiny new “lightweight” ORM all the cool kids are using working properly in your environment, but then somehow it does.

My goal here was to see just how difficult getting up and running with ASP.NET 5 on my Mac and on a Linux box would be. How many errors would I run into? What forgotten step or missing environment variable would make me lose three hours of my life trying to figure out what was wrong? What cryptic error message would I see that doesn’t show up in a Google search?  How bad would the stress headaches be? Would I be vomiting up blood 16 hours into fixing a bad install?

With Visual Studio Code they have also developed a lightweight, cross platform IDE that I decided to try out as well.

Finally, I noted that Microsoft is now offering an option to run ASP.NET 5 apps via command line in Windows, without having to install Visual Studio, so I decided to give that a go as well. Windows command prompt, Mac OS X and Ubuntu terminals… That’s a lot of keyboard action. Hence the title of this post.

Although I did encounter several issues, overall I was pleasantly surprised. The process was much smoother than I expected.

Before continuing, you should understand a few basic terms specific to the new .NET:

  • DNX: .Net Execution Environment (the new .NET runtime basically)
  • DNVM: .Net Version Manager (select and manage DNX versions)
  • DNU: DNX Utility (package management tool for .Net apps)

For more detail, see Microsoft’s DNX  overview.

Caveat: ASP.NET 5 is still under development and constantly changing at the time of this post. If you try to reproduce the steps I used it is entirely possible you may see different behavior or errors. Keep that in mind.

Now, with all of that out of the way, let’s see how it all went.

My Environment

My experiment was conducted on a Macbook Pro running OS X Yosemite  – v 10.0.3. I used Parallels to create the different VMs I used to test the process.

I set up a Windows 8.1 VM so I could install ASP.NET 5 via Visual Studio the old fashioned way as a control scenario before playing with OS X and Ubuntu. I had a Windows 7 VM I’d already been using and did the command line install for Windows sans Visual Studio on that machine.

Since I have heavily abused my trusty Mac, after going through the installation process I spun up an OS X VM so I could repeat it on a clean system, without having to worry if my existing configuration somehow affected the process. I only noticed a couple of minor differences which I’ll make a note of.

Finally, I created an Ubuntu 14.04 VM to try it out on Linux.

Getting Started on Windows with Visual Studio: The Control Scenario

Before diving into uncharted waters I decided to try out ASP.NET 5 in a familiar environment.

Following Microsoft’s instructions, I tried out ASP.NET 5 on Windows by downloading and installing Visual Studio 2015 RC (Enterprise Edition) on a Windows 8.1 VM.

The download and installation took a while, seemed to be almost done and finally hung at “Configuring your system. This might take a while.” The message didn’t lie. It did take while. I waited over an hour before I finally gave up.

Hung VS Install - Screen Shot 2015-06-04 at 8.10.08 PM
How long will it take to configure my system Microsoft? HOW LONG?!?!
Since I like to live dangerously, I decided to take a chance and hope the installation had really finished and that it would still work if I pulled the plug. I tried to cancel the installation (at least, that’s what I assumed the ‘Cancel’ button was for) but it didn’t actually do so – it just kept right on going.

Then I killed it in task manager and tried to open VS 2015 from the start menu, but I got an error that I couldn’t open it since setup was still running – even though I had just killed it in task manager and no process appeared.

Ah, this was the good old Microsoft we’ve all come to know and love.

At this point I defaulted to the old rule of thumb: when in doubt, reboot. So I restarted the VM. Much to my surprise, after Windows rebooted the Visual Studio installation suddenly resumed and this time it actually completed. I was, like ‘woah’.

Once it completed I was able to open VS 2015 from the start menu and started the “Your First ASP.NET 5 Application Using Visual Studio” walk through.

When creating new project, I did spot a small bug – note the Asian characters at the bottom right in the following screen shot. Not being knowledgeable in Asian alphabets I don’t know what language this was, so if you know and would like to leave a comment, please enlighten me.

New Project asian chars - Screen Shot 2015-06-04 at 8.40.10 PM

Reading English is already hard enough for me Microsoft.
Reading English is already hard enough for me Microsoft.
Other than that, the rest of the walk through went smoothly and I didn’t have any problems. I was able to get a bare bones “Hello World” type ASP.NET 5 Web app up and running.

I did note two things that might surprise another n00b like myself:

  • One of the coolest new features in ASP.NET 5 is the ability to make code changes and have them immediately show up on refreshing the browser but without rebuilding the whole application. This didn’t seem to work for me at first – then I went back and reread the instructions and also checked Stack Overflow and realized you had to run the app WITHOUT debugging to use this feature.
  • I noticed that if you make a change to project.json, the new and improved framework immediately tries to execute a ‘dnu restore’ command and update project dependencies on the fly. Something to be aware of.

Aside from a sluggish installation and a label from the wrong language appearing on the screen, I didn’t have any other problems doing it the old fashioned way. Visual Studio and its installation process isn’t that different, so if you’re sticking with Windows and Visual Studio “Getting Started” with ASP.NET won’t be too different from previous versions up to this point.

With the control scenario out of the way, I moved on to the main event.

Getting Started on Windows With a Command Line

Microsoft’s Installing ASP.NET 5 on Windows walkthrough also included instructions for doing so without Visual Studio. I decided to give it a try before moving on to OS X and Ubuntu. Run ASP.NET without Visual Studio? “Impossible!” I shouted out loud. After my coworkers stopped staring at me I gave it a shot and confirmed that it is, in fact possible.

As instructed, I opened a command prompt as Admin and ran the following command to download and install the DNVM:<br></br>

@powershell -NoProfile -ExecutionPolicy unrestricted -Command "&{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}"

No errors – so far so good.

Screen Shot 2015-06-10 at 3.42.59 PM
Oh Command Prompt, I wish I knew how to quit you.
Next I opened a new command prompt and verified DNVM was working by typing dnvm .

I saw the expected result indicating DNVM was installed, but also got an interesting error:

Red is usually bad.
Red is usually bad.
I Googled the error but didn’t find anything relevant, so I decided to try to keep going and see what happened.

The next step was to install the DNX by running dnvm upgrade  and I got another error.Screen Shot 2015-06-10 at 4.02.34 PM

I then tried dnx to see if DNX was installed in spite of this error, and it seemed that it was:Screen Shot 2015-06-10 at 4.08.17 PM

Then I cloned the source from https://github.com/aspnet/home so I could try running one of their sample apps. (NOTE: I used the sample apps in the 1.0.0-beta4 folder since I suspect those in the ‘latest’ folder are more likely to be unstable.)

I switched into the HelloMvc sample app directory and ran dnu restore
which seemed to run successfully.

I then ran dnx . kestrel  and it looks like it worked – it started, but only after a nice security warning from Windows popped up:

Once I allowed access I was able to view the site in my browser at http://localhost:5004/

Screen Shot 2015-06-10 at 4.27.33 PM

QAPLA’! Now I had a Hello-World ASP.NET site running without ever touching Visual Studio.

The errors I got installing the DNX do not seem to have been fatal. A cursory Google search didn’t reveal much. I took a quick look at the code, but I’m not sure what the problem is. The affected block of code in the ‘dnvm’ powershell script appears to be intended to spit out a list of DNVM commands.

The next day I tried it again and while I still get the first error when running dnvm  from a command prompt, I no longer get the second error when running  dnvm upgrade.

Hmmm. These errors don’t seem to have an effect, but one never likes to see strange errors on a new product.

Here’s a step by step summary of the process described above:

  1. Open a command prompt as administrator
  2. Download and install DNVM: @powershell -NoProfile -ExecutionPolicy unrestricted -Command "&{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}"
  3. Confirm DNVM is installed: dnvm
  4. Install latest version of DNX: dnvm upgrade
  5. Get Microsoft’s sample ASP.NET code: git clone https://github.com/aspnet/home
  6. CD to the source folder of whichever sample app you want to run and load dependencies: dnu restore
  7. Start Kestrel: dnx . kestrel
  8. View the site in your browser at http://localhost:5004/

I noticed there didn’t seem to be a way to scaffold out a new solution in any of Microsoft’s docs. So that confused me a bit. Later, I learned about Yeoman, but we’ll get to that shortly.

Now that we’re all suitably impressed that we can run ASP.NET via command line in Windows, in our next post we’ll move on to OS X. Subcribe to TechTalkDC.com for updates and follow @techtalkdc. Stay tuned.

brian-palladino

Washington DC area software developer and consultant currently focused on .NET and Ruby tech stacks