Migrating To Dotnet CLI From DNVM, DNX And DNU For ASP.NET Core

Migrating to Dotnet CLI

Most of us are aware that ASP.NET 5 has been renamed to ASP.NET Core. After that Microsoft has planned to use Dotnet CLI instead of DNVM, DNX, and DNU in RC2. I want to clarify that RC2 is not yet officially released, only nightly builds are available. In this article, I will explain how we can go for migration and will also compare the similar commands in Dotnet CLI which we are having with DNVM, DNX and DNU.

Dotnet CLI

.NET Command Line Interface (CLI) is a tool used for building .NET Core application and libraries. We can download and install CLI from the following  path. For Mac and Linux installation you can visit the link. I am installing it for Windows but you can install it for Linux and Mac as well. After downloading the .exe file for windows execute the .exe file and install it.

Dotnet CLI

Now I will create two applications side by side and compare them. The first application will be created using DNVM, DNX and DNU and I will use Yeoman as scaffolding tool.

Creating ASP.NET Core RC1 application using Yeoman, DNVM, DNX and DNU

Now go to run and type "cmd” to open command prompt and change the directory where you want to create the project.

Now write "yo aspnet” on command prompt (If you are not aware of installing visual studio code and yeoman then go through the following article ASP.NET 5 with Open Source - Part 1).

yo aspnet

Select Console application and give the name "ConsoleApp_ASPNET_RC1".

It will create a console application and provides the list of commands like "dnu restore”, "dnu build”, dnx <Your App Name>. You can refer to  the below screenshot for details.

dnu restore

Now do the following things:

  1. Change the current working directory to "ConsoleApp_ASPNET_RC1” i.e. type "cd ConsoleApp_ASPNET_RC1” on command prompt.

  2. Use "dnu restore” for restoring package and managing dependencies.

  3. Run "dnu build” i.e. type "dnu build” on command prompt.

  4. Type "dnx ConsoleApp_ASPNET_RC1” on console window and inthe next line you will get the output where "ConsoleApp_ASPNET_RC1” is the name of the console application

    C:\Users\DELL INSPIRON 15\ConsoleApp_ASPNET_RC1>dnx ConsoleApp_ASPNET_RC1

    Hello World

If you are creating a web application in that case you do not need to givethe  application a name you need to use the command "dnx web”.

Creating a Console Application with Dotnet CLI

Now go to run and type "cmd” to open command prompt and change the directory where you want to create the project with Dotnet CLI.

  1. Type mkdir "Console App folder Name” e.g. mkdirConsoleAppwithDotNetCLI.

  2. Type "cd ConsoleAppwithDotNetCLI” to go to newly created directory.

  3. Type "dotnet new”to create new console application e.g. D:\2016\ConsoleAppwithDotNetCLI>dotnet new.

  4. Now type "code .” to open the code in Visual Studio code editor.

Visual studio code editor

In Visual Studio code write the following code:

  1. using System;  
  2. using static System.Console;  
  3. namespaceConsoleApplication  
  4. {  
  5.     public class Program  
  6.     {  
  7.         public static void Main(string[] args)  
  8.         {  
  9.             WriteLine("This is my First Console Application with Dotnet CLI");  
  10.         }  
  11.     }  
  12. }  
Now save and go back to the command prompt.

On command prompt type "dotnet restore” e.g. D:\2016\ConsoleAppwithDotNetCLI>dotnet restore.

After the command completed type "dotnet run” e.g. D:\2016\ConsoleAppwithDotNetCLI>dotnet run.

And you will get the following output:

This is my First Console Application with Dotnet CLI

Refer the following screenshot for more details.

dotnet run

So I have used the following command in case of DNU,DNX and DNVM

"dnu restore
”, "dnu build”, "dnx web”or "dnx <console appName>

And for Dotnet CLI I have used,

"dotnet new”, "dotnet restore” and "dotnet run”

We can also use the command like "dotnet publish” or "dnx publish”.

For more details of DNX, DNVM and DNU you can go through ASP.NET 5 with Visual Studio Code: Part 2.

But Dotnet CLI is still in very early development phase and a lot of changes may be done later for roadmap. DotNet CLI will support ASP.NET Core from RC2.

You can learn more about ASP.NET Core from these articles:

Up Next
    Ebook Download
    View all
    View all