/ asp.net 5

Creating an ASP.NET 5 Class Library with Vim

One of the great things about ASP.NET 5 (aka vNext) is that there is no longer a reliance on Visual Studio. I definitely think VS is a great IDE, but it does have it’s quirks and people love options; the option of not having to use VS is a very good option. Also, since ASP.NET 5 can be developed and run on OSX and Linux, users of the *nix OS’s are able to use whatever editor they want.

One thing you might be wondering is: If I don’t have VS, how to I create a project? In current versions of VS/ASP.NET, you open VS and hit File->New Project, give it a name and VS generates a bunch of junk for you. If you don’t have VS, how do you generate that bunch of junk?

Beauty in simplicity

One of the design goals of ASP.NET 5 was to simplify the project structure and remove the hell that is the .csproj file. All that is required now for an ASP.NET 5 project is a project.json file. The csproj file (now a .kproj file in VS 2015) is solely a VS thing and is only necessary if you want to use Visual Studio.

You can, obviously, still use VS to generate projects and it will work great and you can be on your way. But what if you don’t want to use VS? (or are on *nix?)

You have 2 options, the first being to use another generator. One example of a generator is generator-aspnet, which uses the popular Yeoman scaffolding tool.

The other option, which is way more fun, is to create the project yourself.

Creating an ASP.NET 5 project with Vim

We’ll create a simple class library to show how stupidly easy it is, and all we’ll use is Powershell/Vim.

First, create a directory for your project:

C:\Projects> mkdir ClassLib
C:\Projects> cd ClassLib

Next, create a project.json file:

C:\Projects\ClassLib> vim project.json

..and add the following contents (I promise, this is it!):



Create a file for a class:

C:\Projects\ClassLib> vim MyClass.cs

… with the following contents:

namespace ClassLib
    public class MyClass
        public int Number { get; set; }

And finally, build it:

C:\Projects\ClassLib> kpm build

This will build the library as a nuget package and place the nupkg and all files in the \bin\Debug path.

That’s it! It’s worth noting that this is compiling against .NET 4.5 full and is using dependencies from the GAC. You can specify the framework/dependencies in the project.json file if you want to use aspnet50 or aspnetcore50. For example, to compile against aspnetcore50, you can specify it like so:

    "frameworks": {
        "aspnetcore50": {
            "dependencies": {
                "System.Runtime": "4.0.20-beta-22231"

You can review the project.json schema here: https://github.com/aspnet/Home/wiki/Project.json-file

comments powered by Disqus
David Zych

David Zych

Dave is a dad, husband, programmer, (amateur) photographer, half-Canadian, alumnus of CSUCI, and an overall nice guy.

Read More