First Impressions of ASP.NET and Visual Studio Code on OS X

Introduction

At Build 2015, Microsoft has released more tools for .NET developers who own Apple Hardware. I for one love to code in .NET but also enjoy coding Ruby On Rails. In this article, I’m trying to get my first ASP.NET project run on OS X Yosemite.

Installing Mono

The first task is to install the latest version of Mono. To do this I am using Homebrew . If you current have Mono version 3 installed, you might need to force uninstall it first.

To check the Mono version, you can run

mono --version

And to remove it

brew uninstall --force mono

To install Mono you can run

brew install mono

Afterwards you can check the version again with mono --version and you should see

Mono JIT compiler version 4.0.1 (tarball Mon Apr 27 01:00:48 PDT 2015)

Install DNX (.NET Execution Environment) via DNVM (.NET Version Manager)

brew tap aspnet/dnx
brew update
brew install dnvm
echo "source dnvm.sh" >> ~/.bash_profile
source ~/.bash_profile
dnvm upgrade

Install KestrelHttpServer

brew install libuv

Making sure you running on latest version of DNX. Run following command to list all DNX versions

dnvm list

In my case, 1.0.0-beta5-11749 is latest update, so I use that:

dnvm use 1.0.0-beta5-11749    

Running the samples

We use sample project available on GitHub from https://github.com/aspnet/home

git clone https://github.com/aspnet/home
cd Home/samples/latest/HelloMvc
dnu restore 

You should see a bunch of output from NuGet.

nuget

After that run web server command

dnx . kestrel

And you can open Url http://localhost:5004

first

Install Visual Studio Code

You can download the .dmg for Visual Studio Code from https://code.visualstudio.com . After installation, you can open the sample directory HelloMvc

result

Troubleshooting

    1. Error System.InvalidOperationException: Unable to resolve project '' from /path/to/directory/ . You should run dnx . kestrel from the project directory.
    2. Error System.InvalidOperationException: No service for type 'Microsoft.Framework.Runtime.IApplicationEnvironment' has been registered . This means you need to update Mono to version 4.
    3. Error Missing method .ctor in assembly . Check version of your DNX by dnvm list .

References

  1. http://www.infoq.com/news/2015/05/NET-Linux-Mac
  2. https://github.com/aspnet/homebrew-dnx
  3. https://github.com/aspnet/dnvm
  4. https://github.com/aspnet/DNX
  5. https://github.com/aspnet/KestrelHttpServer
  6. href=”https://github.com/aspnet/Home/issues/518″