How to Open .Net Core Projects Created Using Command Line Tooling In Visual Studio 2015

Visual Studio 2015, .Net Core, Cross Platform

3.32 ( 234 votes) | 1287

Introduction:

In this article, we will talk about how to open .Net Core projects created using command line tooling in Visual Studio 2015. To know more about .Net Core command line tooling, refer to my article on Getting Started With .Net Core Command Line Tooling. In this article, we will create a simple .Net Core console application using command line tooling and then will see how to open that application in Visual Studio 2015.

Prerequisite:

  1. Download .Net Core.

Steps:

  • First step is to create a simple .Net Core console application. To create a console application,  open command prompt and execute below command to create a new folder called HelloWorld on any drive.
mkdir HelloWorld
  •  Execute the following command to switch to our newly created folder.
cd HelloWorld
  •  After that, execute the following command to create a simple console application using .Net Core command line tooling.
dotnet new or dotnet new -l C# -t Console
  •  In above command –l parameter specifies the language for the project and –t specifies the type of project. Output of the above command is as shown below (F: 1) (Note: Console application is the default project template and C# is the default language if we don`t specify –l and –t parameter values explicitly when we execute dotnet new command.)

Create .Net Core Console Application

  • As we can see in above image, we have successfully created a new console application. Type dir command and hit enter to see the numbers of files in our new project. Output is as shown below (F: 2).

.Net Core Console Application Project Files Initially

  • As we can see in above image, our new project just contains two files: Program.cs and  project.json. Now let`s see the content of Program.cs file. Execute the following command in command prompt to see the content of Program.cs file.
type Program.cs
  •  Output of above command is as shown below (F: 3)

Content Of Program.cs File

  • As we can see in above image, our console application will simply print out Hello World message to the console. Now execute following command to restore the packages required to build and execute our console application.
dotnet restore
  •  Output of above command is as shown below (F: 4)

Restore NuGet Packages

  • Now to run the application, execute the following command in command prompt.
dotnet run
  • Output of above command is as shown below (F: 5)

Output Of Console Application

  • As we can see in above image, Hello World message is printed out to the console app.
  • Now to open this console application in Visual Studio 2015, normally we need a file with .sln (Microsoft Visual Studio Solution) extension. Let`s check the files in our project one more time (F: 6)

Console App Files Before Opening The Project In Visual Studio 2015

  • As we can see in above image, we don`t have a file with .sln extension.
  • Now open Visual Studio 2015 and use shortcut key Ctrl+Shift+O to open the project. After using the shortcut key, Visual Studio will open up a dialog box. Using that dialog box, navigate to our HelloWorld directory and select the project.json file and then click on Open button. Visual Studio will load that project. Output is as shown below (F: 7)

.Net Core Console Application Loaded In Visual Studio 2015

  • Files in our project after loading the project in Visual Studio 2015 are as shown below (F: 8)

.Net Core Console App Extra Files Are Created After Opening Project In Visual Studio 2015

  • As we can see in above image, two new files got created after we loaded the solution in Visual Studio 2015. But still we don`t have a file with .sln extension. Now to create a file with .sln extension, go to File menu and select Close Solution option. When we try to close the solution Visual Studio will display the following prompt to save solution file (.sln) as shown below (F: 9)

Save .sln File For .Net Core Console App

  • Click on Yes button. After clicking on Yes button Visual Studio will display another dialog to save the solution file (.sln) in our HelloWorld directory as shown below (F: 10)

Save Microsoft Visual Studio Solution File In Project Dirctory

  • Click on save button to save the .sln file for our console application. Files in our HelloWorld console application after saving the .sln file are as shown below (F: 11).

Solution File For .Net Core Console Application Is Created

  • As we can see in above image, now we have HelloWorld.sln file, which we can use to open our console application in Visual Studio 2015 next time.

Video:

Conclusion:

In this article, we talked about how to open .Net Core projects created using command line tooling in Visual Studio 2015. I hope you enjoyed reading the article.

Happy Coding!

Manoj Kulkarni - Dotnetcontext

Manoj Kulkarni

I am programmer, passionate blogger and foodie. I live in Nashik. I am a .Net developer. I like to learn new technologies to keep my self-updated and share that knowledge with my blog readers, friends and colleague.

Add a new comment