Getting Started With .NET Core With Windows And Visual Studio 2015 Part - One

.NET Core is an open-source and cross-platform development environment developed by Microsoft. As we already have a couple of articles explaining what is.NET Core, its design principle, and architecture; we will focus more on developing, deploying, and exploring the features of.NET Core.

To create a.NET Core application, we will require the following tools.

  1. Visual Studio 2015
    You can download the free edition of Visual Studio called “Community Edition”. Click on the   “Free Download” button under the panel of Visual Studio Community and install the same.

  2. .NET Core
    As we are done with VS, we will now require .NET Core for creating an application. You can refer to the following link to download and install.

Let's create our first application with .NET Core on Windows with Visual Studio 2015. We will create a simple class library using .NET Core.

Step 1

Open the Visual Studio 2015 and select New Project:

visual Studio

Step 2 - Add .NET Core Class Library

Select .NET Core under the template section and select the Class Library (.NET Core). Give an appropriate name to the project and click on the OK button. In our case, we have given it the name “DotNetCoreDemo”.

visual Studio

visual Studio

Once you click on OK, you will get the following screen. A new project is created under the “src” folder.

visual Studio

Step 3

Play with some code. Replace the constructor with the following lines of code.

  1. public string GetMessage()  
  2. {  
  3. return "Hello World!";  
  4. }  
Our program will look like the following.

visual Studio

Save your changes and build the application. You can use “Ctrl + Shift + B” as a shortcut to build the same. Your application should be built successfully without any errors.

With this, we have created a simple application which will return “Hello World”.

Step 4 - Using the Class Library

Now, to use the above mentioned project, we will create a console application using .NET Core.

Go to Solution Explorer, right click on “Src” folder, and add the new project.

visual Studio

Click on “New Project” from the above mentioned step or screen.

Select .NET Core from the left panel and click on “Console Application (.NET Core)”. Give appropriate name and click on OK button. In our case, we have given the name as “DotNetCoreApp”.

visual Studio

visual Studio

You can see, a new project under “Src” folder is created with the name “DotNetCoreApp".

Step 5 - Consume the code from .NET Core class library

In order to use the class library, we need to add reference of that project into our console application. Right click on “References” and select the “Add Reference..” option.

visual Studio

You will see that a dialog with “Reference Manager” title gets opened. Check the checkbox near to solution, named as “DotNetCOreDemo” and click on OK button.

visual Studio

Now, to consume the code, we need to add “using DotNetCoreDemo;” to Program.cs file. Also, add the following line of code under the main method.

Console.WriteLine(new Class1().GetMessage());
Console.ReadLine();

Our program will look like the following.

visual Studio

Now, set your console application (DotNetCoreApp) as Startup Project and build the Solution. Your solution should built successfully without any error.

Step 6 - Time to see the output

Click on F5 to see the output.

visual Studio

What we have learned so far
  1. How to create class library using .NET Core
  2. How to create console application using .NET Core
  3. Consume the class library in console application.

I hope this article will help you to understand the creation of simple applications. In the next article, we will learn how to add  a test project and test our class library created using .NET Core.

Reference

For prerequisites, visit https://docs.microsoft.com/en-us/dotnet/articles/core/windows-prerequisites


Similar Articles