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

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 please 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 the 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 the 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.)

dotnet

As we can see in the 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 of dir command is as shown below (F: 2).

dotnet

As we can see in the 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 the above command is as shown below (F: 3)

dotnet

As we can see in the above image, our console application will simply print out Hello World message to the console.

Now execute the 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)

dotnet

Now to run the application, execute the following command in command prompt.

dotnet run

Output of above command is as shown below (F: 5)

dotnet

As we can see in the 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)

dotnet

As we can see in the 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)

dotnet

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

dotnet

As we can see in the 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)

dotnet

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)

dotnet

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).

dotnet

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

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.


Similar Articles