.NET Core Command Line CLI Basics

Yes, developing .NET apps without opening Visual Studio was something I wish for a long time. It was possible but wasn’t that simple. With .NET Core CLI, managing the project is simpler than ever. Let’s see how we can create a new project, build and run and learn some more commands.

1. Creating a Project/Solution & Adding Project to a Solution

After going to the folder you want to create the project. You can just type

 "dotnet new"

This will not work but you will see the options you can use.

For an MVC project, you can use

 "dotnet new mvc"

For a console app, use

 "dotnet new console"

If you want to create the project in a folder with a solution name you desire, use

 "dotnet new mvc -n MyNewMvcProject"

Once you do any of above, the files for the project will be created and you can jump start working on your projects. Details for the “dotnet new” command can be found here >>>

If you want to add projects under the solution, use “dotnet sln []” command. Click to see more details.

2. Running / Building the Projects

For running the project quickly, use

dotnet run

If you get an error of missing files, you have to restore the packages. Use

 dotnet restore 

This restores the dependencies and tools of a project that are specified in the project file. Note that “dotnet run” command, takes care of compiling and building the project as well. It runs “dotnew build” before it runs.

3. Adding Packages to the Projects & Adding Projects as Reference

You can use “dotnet add package PackageName” to add a package from NuGET. For example, to add Newtonsoft.Json, use

dotnet add package Newtonsoft.Json

You can specify the URL of the package as well:

dotnet add package Microsoft.AspNetCore.StaticFiles -s https://dotnet.myget.org/F/dotnet-core/api/v3/index.json

The commands above must be the most used ones. For all, please visit the official article on microsoft >> .NET Core command-line interface (CLI) tools

Advertisements
This entry was posted in .NET Core and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s