Skip to main content
How to Install ASP.NET Core And Create Your First Application

How to Install ASP.NET Core And Create Your First Application

Finally, ASP.NET Core is out and there is lots of excitement among developers. As you might be knowing ASP.NET Core is completely a new framework and will definitely require some learning. In this post I will take you through about how to install ASP.NET Core along with tooling and then creating your first .NET Core application and ASP.NET Core application using dotnet cli tool.

How to Install ASP.NET Core

Installation of ASP.NET Core is simple but choosing the correct one may be tricky. Follow below steps to install ASP.NET Core.

Please remove previous installation (if you have)

The installer doesn’t override previous installation. So if you already have ASP.NET Core RC1/RC2 installed, then you have to manually uninstall it. So please remove previous installation of,

  • Preview Tooling Preview 1
  • .NET Core Runtime SDK (all versions)
  • .NET Core Runtime (all Versions)

And now download the new installers and install it.

  • As mentioned in my earlier post, there will be a release for tooling (includes dotnet cli) and a separate release for .NET Core and ASP.NET Core 1.0 runtime and libraries. So download the installer based on platform and architecture of your system from here. On that page, you will find a list of various downloads for each platform.You probably only need to download one of these:
    • .NET Core = Run apps with .NET Core runtime.
    • .NET Core SDK = Develop apps with .NET Core and the SDK+CLI (Software Development Kit/Command Line Interface) tools.

    .NET Core RTM installer.pngSo once downloaded, run the installer and this should install .NET core on your system.

  • Download Tooling Preview 2 and install it.
  • You also need Visual Studio 2015. To begin with, you can download Visual Studio Community 2015 for free.

So when installation is finished, you should be able to create .NET Core application from command line.

Create a .NET Core application

Let’s first verify the installation. So go to command prompt and type

dotnet --version

and you should see 1.0.0-preview2-003121 as output. So let’s create a new .NET Core app. It’s very easy to do it using new dotnet cli. So execute following commands.

mkdir FirstNETCoreApp 
cd FirstNETCoreApp
dotnet new      //Creates a new .NET Core application
dotnet restore //Restores all the dependencies.
dotnet run   //Compile and run the application.

And as an output for dotnet run command, you should see “Hello World!” on command prompt. Congratulations for your first .NET Core app. Easy and straightforward. Isn’t?

Create an ASP.NET Core application

With the dotnet cli, you can also create ASP.NET core application as well.

mkdir FirstASPNETCoreApp 
cd FirstASPNETCoreApp
dotnet new -t web   //Creates a new ASP.NET Core application

when you execute dotnet new -t web, you should see following screen,
First ASP.NET Core App using dotnet cliOnce the app is created, you need to restore the references. So execute,

dotnet restore //Restores all the dependencies.

And now, let’s run the asp.net core application.

dotnet run //Compile and run the application.

First ASP.NET Core app runningIn case of web applications, you will have to open the browser and navigate to the URL reported by the dotnet tool. So when you open URL http://localhost:5000, you should see your ASP.NET Core application running successfully in the browser.

ASP.NET Core app running in browser

Create an ASP.NET Core application using VS 2015

Open Visual Studio 2015. Hit File -> New ->Project. With ASP.NET Core, you will see separate templates for ASP.NET and ASP.NET Core project. As you can see in below image. There are 3 options now.

  • ASP.NET Web application (.NET Framework) – Option to create ASP.NET application using .NET Framework 4.6
  • ASP.NET Core Web application (.NET Core) – To create cross-platform ASP.NET application using .NET Core
  • ASP.NET Core Web application (.NET Framework)– To create ASP.NET Core web application targeting .NET 4.6 for windows platform only.

Visual Studio 2015 RC2 Templates -1

Also notice on right-hand side, there is a separate entry for .NET Core templates.

Visual Studio 2015 RC2 Templates -2

In this post, we shall create an ASP.NET Core Web application (.NET Core) option. Once you provide the web application name and hit ok you should see following project template selection dialog. This now lists only those templates that are applied to ASP.NET Core 1.0.

Visual Studio 2015 RC2 Templates -3

Select Web Application and click OK to create the project. Solution explorer should look like shown below.

ASP.NET Core App SolutionExplorer

If you are following ASP.NET Core progress, then I already covered the changes in my post about web.config, new program.cs file and project.json changes with respect to RC2 release. And a few days back, the decision was taken to remove Gulp as the default choice for task runner and it is replaced with BundlerMinifier. And that’s why you see bundleconfig.json in solution explorer.

Hit F5 and run the application. And you should see your application running with the default ASP.NET Core template. Let’s modify the code to display a welcome message on the screen. So open HomeController from the Controllers folder and modify the Index() action as follows:

public IActionResult Index()
{
    ViewBag.Message = "My First ASP.NET Core running successfully!!!";
    return View();
}

Now let’s modify the view to show the message. So go to Index.cshtml from the Views > Home folder and replace the HTML markup with :

<h1>@ViewBag.Message</h1>

And now just run the application and you should see your message in the browser.

ASP.NET Core app running-in-browser

Congrats!!!!

But, there is a difference between the application created via VS 2015 and using dotnet cli. As Gulp is no longer the default choice as task runner and that’s why you don’t find gulpfile.js in solution explorer compare to RC2 project. But if you open the ASP.NET Core project created via dotnet cli, you will find gulpfile.js present in the directory.

dotnet cli tool created asp.net core applicationIt seems that dotnet cli is using ASP.NET Core RC2 template for ASP.NET Core project (at the time of writing this post).

You can also use Yeoman to create ASP.NET Core web application.

Summary

In this post, I showed you how to install ASP.NET Core and tooling and also how to create a simple .NET Core application and ASP.NET Core application. Thank you for reading and I hope it helped you. Keep visiting this blog and share this in your network. Please put your thoughts and feedback in the comments section.

4 thoughts on “How to Install ASP.NET Core And Create Your First Application

  1. Thanx a lot for the article, it helps
    Waiting for deep tutorials such as View Components, Tag Helpers, Filters, …

  2. How to add a Class Library project with nuget package, say targeting Net Framework 4.5, and use this in ASP.NET Core 1.0 project?

    1. If it is your own nuget package and not pushed to nuget.com, then you can extract its content and you will get a dll. Then you need to add reference of that dll (Reference -> Add Reference).

      And if the package is already pushed to nuget.com then use package manager console to download and install it.

Leave a Reply to Leszek Cancel reply

Your email address will not be published. Required fields are marked *

3 + 17 =