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.
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).
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.
Now do the following things:
- Change the current working directory to "ConsoleApp_ASPNET_RC1” i.e. type "cd ConsoleApp_ASPNET_RC1” on command prompt.
- Use "dnu restore” for restoring package and managing dependencies.
- Run "dnu build” i.e. type "dnu build” on command prompt.
- 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.
- Type mkdir "Console App folder Name” e.g. mkdirConsoleAppwithDotNetCLI.
- Type "cd ConsoleAppwithDotNetCLI” to go to newly created directory.
- Type "dotnet new”to create new console application e.g. D:\2016\ConsoleAppwithDotNetCLI>dotnet new.
- Now type "code .” to open the code in Visual Studio code editor.
In Visual Studio code write the following code:
- using System;
- using static System.Console;
- namespaceConsoleApplication
- {
- public class Program
- {
- public static void Main(string[] args)
- {
- WriteLine("This is my First Console Application with Dotnet CLI");
- }
- }
- }
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.
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: