Debugging Mono Applications with VSCode on Mac OS X

Standard

Debugging a Mono AppI wrote in a recent post that Visual Studio Code does not support debugging Mono and ASP.NET 5 applications on Linux or Mac OS X in the preview version which was released last week. As Isidor Nikolic pointed out I’m wrong about Mono. VSCode supports debugging Mono applications. In this post I show how you must configure your launch settings.

When you click on the gear icon on the debug pane VSCode opens .settings/launch.json. Just add the following launch settings and adapt it to your Mono project:

{
    "version": "0.1.0",
    // List of configurations.
    // ONLY "node" and "mono" are supported, change "type" to switch.
    "configurations": [
        {
            // Name of configuration
            // Appears in the launch configuration drop down menu.
            "name": "Launch <PROJECT NAME>",
            // Type of configuration. Possible values: "node", "mono".
            "type": "mono",
            // Workspace relative or absolute path to the program.
            "program": "<PATH TO EXECUTABLE FILE>",
            // Automatically stop program after launch.
            "stopOnEntry": true
        }
    ]
}

After building your Mono application you can set a breakpoint and launch the debugger.

Visual Studio Code – My First Impressions

Standard

Microsoft presented the new Visual Studio Code editor at their annual developer conference Build 2015. It is a code editor and Microsoft’s first cross-platform development tool.

I played around with Visual Studio Code on Mac OS X. This article provides my first impressions with this new tool.

Setup of Visual Studio Code on Mac OS X

The Visual Studio Code documentation contains detailed setup instructions for every platform. For Mac OS X I recommend that you follow all steps including adding the code function to your .bashrc file.

  code () {
      if [[ $# = 0 ]]
      then
          open -a "Visual Studio Code"
      else
          [[ $1 = /* ]] && F="$1" || F="$PWD/${1#./}"
          open -a "Visual Studio Code" --args "$F"
      fi
  }
  

Language Support

Visual Studio Code supports many different programming languages with different set of features:

Features Programming Languages
Syntax coloring, bracket matching Batch, C++, Clojure, CoffeeScript, Dockerfile, F#, Go, Jade, Java, HandleBars, Ini, Lua, Makefile, Markdown, Objective-C, Perl, PHP, PowerShell, Python, R, Razor, Ruby, SQL, Visual Basic, XML
+ Intellisense, linting, outline CSS, HTML, JavaScript, JSON, Less, SASS
+ Refactoring, find all references C#, TypeScript

It looks like the editor targets web developers. I, personally, would like to see better support for F#.

More details about the language support in Visual Studio Code you can find in the official Visual Studio Code documentation.

Command Palette

Do you know the Command Palette in Sublime Text? Visual Studio Code has one, too. It looks like this:

Command Palette in Visual Studio Code

You can invoke commands and navigate to different locations in your project with it. John Papa wrote a blog post series about Visual Studio Code and he provides a detailed introduction to the Command Palette in the second post of the series.

Code Navigation

Visual Studio Code has also some other features for navigating your code. For example, you can find all references of the symbol under the cursor using SHIFT F12. If you work on a C# project you’ll see the “CodeLens” feature which means that you see how many references exist for a symbol.

CodeLens in Visual Studio Code

And if you click on it you’ll see the references in a small popup window:

Expanded CodeLens in Visual Studio Code

Intellisense

Visual Studio Code has great Intellisense support even for JavaScript projects. It can distinguish between different types in JavaScript:

Intellisense for String in Visual Studio Code

You can use TypeScript type definition files for providing more information to Code about different types in third-party libraries. Code can reference those files automatically for you if you use a Code Action (CMD+. on an underlined symbol):

Code Action in Visual Studio Code

If you choose Add /// reference to 'node/node.d.ts' Code will add a comment line at the beginning of the file which is a reference to the TypeScript type definition.

With this line you added Intellisense support for Node even if you don’t write your code in TypeScript.

Code has Intellisense support even for package.json, bower.json, and project.json.

Debugging

Debugging C# applications on Mac OS X or Linux is not supported at time of writing. But the support for Node applications work perfectly.

The first step is to add a launch.json file by clicking on the gear icon on the Debug pane in the sidebar.

After that you can set breakpoints somewhere in your code, e.g. by clicking with the mouse left to the line number, and start debugging by pressing F5.

Debugging an Express App in Visual Studio Code

Git Integration

Git - Changes in Visual Studio Code

Visual Studio Code has Git integration.

After initializing a new Git repository you can commit your changes. You should provide a proper .gitignore file first.

Again, John Papa has a great introduction to Code’s Git integration in a blog post of his series.

Architecture

Visual Studio Code is based on Github’s Electron, the former Atom Shell. Electron allows developers to build cross-platform desktop applications with web technologies. Other applications built with Electron are Atom, Slack, Facebook’s new IDE Nuclide or Kitematic, a GUI application for managing Docker containers.

Code uses a newer and faster version of the same HTML-based editor that was used for the “Monaco” cloud editor, and other projects. And Code uses a tools service architecture that enables it to use Roslyn for .NET, TypeScript, the Visual Studio debugging engine, and more.

Still Missing

Visual Studio Code is still a preview at the time of writing. This means that there are still some features missing. Here is a short list what I’d like to see in the future:

  • Extensibility Features – Microsoft plans to add a public extensibility model to Visual Studio Code that let developers build and use plug-ins.
  • Source Code – I think that a code editor in 2015 should be open source like Emacs, Vim, Atom, or Brackets.
  • Better F# Support – There is syntax highlighting for F# code, but that’s it. I’d like to see more integration with an F# REPL, building F# code, etc.
  • Debugging on Mac OS X/Linux – ASP.NET 5/Mono projects still cannot be debugged on Mac OS X or Linux at time of writing.

Conclusion

I liked working with the preview of Visual Studio Code. It’s fast and it has a minimal set of features required for working with code, like code navigation, debugging and intellisense.

If the missing parts, above all the extensibility features, are added, then I think that Code can be a successful code editor.

Update: As Tim van Wassenhove and Isidor wrote in the comments, Mono applications can be debugged on Mac OS X and Linux. I wrote a blog post how you can configure VSCode for debugging Mono applications.

Why you should join F# Vienna

Standard

fsharp-vienna-400Are you interested in F#, the functional-first open source programming language for .NET and Mono? Do you live in Vienna? Why haven’t you joined F# Vienna at Meetup yet?

Why should you join F# Vienna? Well, there are some reasons:

  1. Connect with other developers who are interested in F#! Get to know each other! Drink beer together! Talk about F#!
  2. Present your projects! You did something interesting in F#? Or did you learn something interesting? Present your project or teach us at one of our meetups!
  3. Learn from other developers! You don’t know F# yet? Well, profit from the experience and knowledge of more advanced developers and listen to one of the talks at our meetups!
  4. Help promote F#! You are excited about F#? Bring your colleagues to one of our meetups so that they can see the advantages!
  5. Get hired to work on F#! My hope is that companies will see that there are developers who are interested in F# and start more F# projects in Vienna. Knowing other programming languages can be an advantage for your job search as well.

What’s coming up next for F# Vienna?

The meetup group is set up and you are able to join. What can you expect for the next few weeks?

Meeting in May

There will be a meetup on May 15th. It’s a Friday and Andrea Magnorsky will join us to facilitate a Coding Dojo where you can practice F# on a small coding problem.

Meeting in June

The second meetup will be in June. The date hasn’t been fixed yet. Join F# Vienna at Meetup and get updates on our meetups.

12 Interesting Podcasts for Software Developers

Standard

Headset lying on a laptop computerAbout 2 months ago I started to listen to podcasts again. They are a convenient way to stay up to date on different topics on my way to and from work.

Although I’m a C# developer by day, I like to listen to podcasts about other programming languages and technologies, too. Here are my favourite software development podcasts:

  • Software Engineering Radio: I highly recommend this podcast to every software developer. The shows are about every aspect of software development and the guests are first-class. New episodes appear every two to four weeks.
  • Donau Tech Radio (in German, actually Upper Austrian dialect): An Austrian podcast by Thomas Einwaller and André Steingreß. They talk about gadgets, software development, and programming. New shows appear usually every one to two weeks. You have to understand German or, actually, the Upper Austrian dialect to follow the show.
  • Herding Code: Hosted by K. Scott Allen, Kevin Dente, Scott Koon, and Jon Galloway. This show started as a .NET development podcast, but the episodes were about different technologies recently. The episodes don’t appear on a regular schedule.
  • JavaScript Jabber: A very interesting show for JavaScript developers. Every week there is a new episode about JavaScript programming.
  • The Web Platform Podcast: A podcast about web technologies. Every week there is a new episode about topics like Flux, React, Polymer, Dart, WebRTC etc.
  • Functional Geekery: Hosted by Steven Proctor, a highly recommended podcast about functional programming. New episodes appear about every month.
  • Mostly Erlang: As the name suggests this show covers Erlang, but sometimes it’s about other functional programming languages, too. There are about 2 episodes every month.
  • The Cognicast: In this Clojure-oriented show Craig Andera talks with developers from different Lisp communities like Clojure, Scheme, or Racket. He publishes about 1-2 episodes every month.
  • The Type Theory Podcast: Static type enthusiasts must like this new podcast. It is a podcast about type theory and its interactions with programming, mathematics and philosophy.
  • The Scalawags: A podcast for Scala developers with very detailed show notes. About 1-2 episodes appear every month.
  • .NET Rocks!: Carl Franklin and Richard Campbell do a very amazing show. The first show appeared on August 30, 2002 and they are already at episode #1042! As the name suggests the main topic is .NET development, but there are often other topics, too. Usually three (!) new episodes appear every week.
  • Hanselminutes: Scott Hanselman hosts a show for developers about a broad range of topics. Every week he publishes a new episode.

Did I miss a great podcast? Leave a comment and tell me which software development podcast I should listen to!

Do you listen to podcasts, too? Use the comment form below and let us see your list of software development podcasts!

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.