How I got ASP.NET vNext running on Mac OS X

Standard

Modern Slim MacBook Pro on White BackgroundThe next version of ASP.NET MVC (ASP.NET vNext) will run on a “cloud-optimized” platform which will work on Linux and Mac OS X with Mono, too. Here is how I got it running on my MacBook.

Important Note: ASP.NET vNext is still work in progress and it may not work as intended. Please do not use it in production!

Required Mono Version and Basics of K Runtime

First I installed Mono from source, because the current stable version (Mono 3.4.0) is not sufficient to run ASP.NET vNext applications. This will change when the next stable version of Mono is released. Then I installed the K Version Manager (KVM). KVM is used to manage different versions of the K Runtime the ASP.NET vNext runs on. Graeme Christie and Simon Timms blogged about how to install Mono from source and the KVM.

How you can use KVM to manage different versions of the K Runtime on your machine? Type kvm to see a list of available commands. The most important commands are:

  • kvm upgrade: Installs the latest KRE (K Runtime Environment).
  • kvm list: Lists the installed runtime environments.
  • kvm use: Switches to a specific kRE version.

A Simple “Hello, World” Program

Type kvm upgrade to install the latest KRE. Then create a file somewhere on your disk with the name “project.json” and the following content:

{
  "dependencies": {
    "System.Console": "4.0.0.0"
  },
  "configurations": {
    "net45": {},
    "k10": {}
  }
}

Create another file in the same directory with the name “Program.cs” and the following C# program as content:

using System;
  
public class Program
{
    public static void Main()
    {
        Console.WriteLine("Hello, World!");
    }
}

The first file is the project file. It contains the dependencies and describes the runtime configurations. The dependencies are NuGet packages. You can use the K Package Manager (KPM) to work with the packages. Type kpm help or kpm to get an overview of the kpm commands. Restore the packages by typing kpm restore now and run the program with k run.

When I was experimenting with ASP.NET vNext I ran into some errors:

  • System.AggregateException: —> System.IO.IOException: Too many open files“. Solution: increase the maxfiles limit of your system:
> launchctl limit maxfiles 16384 32768
  • Could not load type ‘System.Reflection.Internal.MemoryMappedFileBlock’ from assembly ‘System.Reflection.Metadata, Version=1.0.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’.System.Reflection.Internal.Metadata” Solution: Check the Mono version with mono --version and make sure that the correct version of Mono can be found in your PATH variable.

ASP.NET MVC Project Generator for Yeoman

An MVC application consists of controllers, views, model and configuration files and maybe other files needed by the program. A scaffolding tool can create new projects from a template or a generator. One of those tools is Yeoman and Hassakarn C. wrote an ASP.NET MVC Project Generator for Yeoman which can create projects for ASP.NET vNext.

If you want to use Yeoman you’ll have to install Node.js. Follow the instructions on its homepage. It comes with NPM, the Node Package Manager, which you can use to install Yeoman and the ASP.NET MVC Project Generator:

> npm install -g yo
> npm install -g generator-aspnet

You can create a new project for the K Runtime by running:

> yo aspnet

Then you can select the type of application you want to create.

Screenshot ASP.NET MVC Project Generator for Yeoman

If you create a console application, you can run your program with k run. It is the same application we built before without Yeoman.

k run runs the program by invoking its entry point, a static method called Main. An MVC program doesn’t have such a method. When you open the “project.json” file of the MVC application you’ll find a section called commands:

...
  "commands": {
    "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5001",
    "kestrel": "Microsoft.AspNet.Hosting --server Kestrel"
  },
...

This section defines commands which you can use instead of run when you invoke k. As you can see there are two commands defined: web and kestrel. web invokes a server used for self-hosted ASP.NET programs. It doesn’t work on OS X yet. But you can use the alternative Kestrel server which is a libuv-based HTTP server for .NET.

You can run your MVC application with Kestrel with this command:

> k kestrel

The default port is 5000. If you navigate your browser to http://localhost:5000 you should see the default welcome page of ASP.NET vNext.

If you try to start the application with k run you’ll get an error with the following message: “<appname> does not contain a static ‘Main’ method suitable for an entry point“. So make sure that you type the right command for your type of application.

Creating Nancy Projects with Yeoman

Inspired by the Yeoman generator for ASP.NET MVC Jonathan Channon created a generator for the Nancy framework. Nancy is a lightweight framework for building HTTP based services on .NET and Mono. You can install the generator via npm:

> npm install -g generator-nancy

For creating a Nancy project type the following into your terminal:

> yo nancy

The generated project contains a simple Nancy module which is hosted on Kestrel with the OWIN interface. You can start the Nancy application with the k command:

> k kestrel

Using Sublime Text 3 for Working With ASP.NET vNext Projects

One of my favorite text editors is Sublime Text. It can be extended by plugins and Sourabh Shirhatti started working on an extension for ASP.NET vNext, called “Kulture”. He demonstrates the extension in a YouTube video.

You will need Sublime Text 3 which is still in beta and the Package Manager for Sublime Text 3 if you want to try it. Then press Cmd-Shift-P which opens the Command Palette and select “Package Control: Install Package”. Then select “Kulture” from the package list.

The extension configures the Sublime Text Build System for builds with the K Runtime. When you opened an ASP.NET vNext project from the project directory you can build it by pressing Cmd-B. If there are compilation errors you can cycle through them with F4. And with Cmd-Shift-P you can select “Run K Commands” and start one of the commands defined in the project.json file.

Summary

With ASP.NET vNext Microsoft tries to build ASP.NET on a new platform which can be run on UNIX like operating systems like Linux or Mac OS X. In this article I showed you how you can install it and how you can run a simple “Hello, world!” program. I introduced you to the Yeoman scaffolding tool and two generators, one for creating MVC apps and one for creating Nancy apps. Finally I showed you an extension for the popular Sublime Text editor.

It’s interesting to see new ideas coming from the community. I’m curious how the new tools will evolve and how creating applications on ASP.NET vNext and Mono will look like in a few months.

Introduction to the Elm Programming Language

Standard

designer drawing website development wireframeElm is an interesting new programming language. Its goal is to make web GUI programming a great experience. It compiles the source code to JavaScript, HTML, and CSS.

Elm is a functional programming language. Its main influences are Haskell, OCaml, SML, and F#. Elm is strongly statically typed and it uses type inferencing. You don’t have to specify the type for variables and parameters like in C# or Java. Elm is built on the Haskell platform and has a Haskell-like syntax, though semantics are closer to OCaml.

I want to show you some basic features of Elm in this post. I’ll write some more posts about Elm in the next few weeks.

Hello, world!

You will find an online editor on the Elm homepage where you can try out the programming language. Just click “Try” and you’ll get to the online editor. On the left side you’ll see the editor and on the right side the result when you run the program. You can run the program by clicking on “Compile” (below the editor).

We’re learning a new language and the first program in a new language is usually a “Hello, world” program. It looks like this in Elm:

    main : Element
    main = plainText "Hello, world!"

main defines the entry point of the program. It is of type Element which represents a rectangle on the screen with a known width and height. Elements are combined to define complex widgets and layouts. The type is defined in the library Graphics.Element which is imported automatically when the program starts.

The first line of our program is the type signature. It defines the name and its type separated by a colon. The entry point has the name “main” and Element is its type. The type signature is optional.

The second line is the code. "Hello, world!" is a string. The function plainText converts the string to an element. You can see, that you don’t need braces for calling a function.

Here is another version of the hello world program:

    main = asText "Hello, world!"

Did you notice the difference? The second program prints the string “Hello, world!” with quotes and the first program without quotes. The first version uses the function plainText to convert the string to an element. plainText takes a string and creates the Element from the string value.

The second program uses asText which takes any value and uses its string representation for creating the Element. The string representation of a string includes the quotes and the value does not.

    main = asText (4,5)

This program prints the string representation of the tuple, “(4,5)”. A tuple is an ordered list of elements. The tuple above contains two integer values, 4 and 5. If you change asText to plainText you’ll get a type error. plainText expects a string as parameter, but (4,5) is a tuple.

Elm is reactive

Elm has an interesting type called Signal. A signal is a value which changes over time. Let’s see it in action:

    import Mouse

    main : Signal Element
    main = lift asText Mouse.position

The first line imports a library for working with mouse input called Mouse. The second line is the optional type signature. As you can see the type of the entry point main has changed to Signal Element. This means that output of the program can change over time.

The Mouse module contains a signal called position of type Signal (Int,Int). Every time the mouse is moved its value changes. The value is of type (Int,Int) which is a tuple with two integer numbers. It represents the current mouse position on the screen.

The function lift takes a function as first argument and a signal as second element. Every time the signal is updated the new value is applied to the function and its return value is used as new value for the signal returned by lift. We use asText as function so that lift converts each tuple with the mouse positions to a string when the mouse position changes.

I showed you how a basic hello world program looks like in Elm and I introduced you to Elm’s concept of signals. I will focus on the functional nature of the language in my next post about Elm.

The 25 Most Interesting Links about ASP.NET vNext and the K Runtime

Standard

What is nextMicrosoft revealed its plans for the next generation of .NET at the TechEd North America in May. The next version of ASP.NET will bring some interesting features for ASP.NET web developers:

  • It will be fully open source.
  • ASP.NET MVC, ASP.NET WebAPI and SignalR will be integrated into one framework.
  • Multiple versions of the runtime can be installed side-by-side.
  • It runs on Mono, on both Linux and Mac OS X.
  • No dependency on System.Web.
  • Better support for development with text editor and command line tools.

I collected some links for more information and details about this topic.

Blog posts about ASP.NET vNext and the K Runtime

Videos about ASP.NET vNext and the K Runtime

Blog Reorganisation

Standard

BlogI migrated my blogs back to WordPress. I started blogging with self-hosted WordPress blogs about 8 years ago. Some years ago I began using Disqus for comments and switched one blog to Octopress. I migrated both blogs to Pelican one year ago. Now I’m back at WordPress. While I was migrating the blogs I decided to merge my two blogs andreas-schlapsi.com (English blog) and andreas-schlapsi.at (German blog) to one blog at schlapsi.com and redirected the URLs from my old blogs to this one. I plan to write here in English. Maybe I’ll write something in German here every now and then.

Why did I switch to WordPress again? Jeff Atwood said, a blog without comments is not a blog and not having a decent comments system was one of the biggest disadvantages when I used a static site generator. I didn’t want to save the comments on another system operated by a commercial company like Disqus.

I found a way to write my posts in Markdown on WordPress. Not being able to write in Markdown was the biggest issue I had with WordPress and the number one reason why I migrated my blog away from WordPress.

I wanted to improve the themes of my old blogs, but I didn’t have enough time to work on them. I guess it’s easier to use one of the available WordPress themes instead of creating my own theme.

But there are also some downsides: first I need to run server software which needs more server performance than a static site. There are solutions which can improve the situation.

Second I still don’t like the editor. There are blog editors out there. Maybe I’ll try out some of them.

Of course, I had a look at Ghost, but it wasn’t as mature as WordPress. It didn’t have a comment system, too. It looked very nice and promising, though.

Official End of the RowTest Extension

Standard

I published my RowTest extension for NUnit in 2007. I developed it to experiment
with the NUnit extension mechanism which was new in NUnit 2.4. It got some users
and the extension was included in NUnit 2.4.8. NUnit 2.5 had the new Test Case feature
which was built on the experience gained by the RowTest extension.

To switch from RowTest to TestCase you just have to replace the RowTest attribute by the TestCase attribute.

Since the RowTest extension isn’t needed anymore I stopped its development long time ago. I just didn’t publish an official statement about its end. I will remove the RowTest project page on my blog, but the project pages on Google Code and Launchpad will still be available: