Sunday 19 June 2016

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

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

 

It've been adding support for a growing number of operating systems. We started out the project with a plan to support .NET Core on Windows, OS X and Linux. Close watchers of the coreclr and corefx projects will have noticed that the platform support has been growing steadily. .NET Core RC2 is supported on the following platforms.
  • Red Hat Enterprise Linux 7.2
  • Centos 7.1
  • Debian 8.2+
  • Ubuntu 14.04 (16.04 support is coming at RTM)
  • Linux Mint 17+
  • OS X 10.11
  • Windows 7+ / Windows Server 2012 R2+
  • Windows Nano Server TP5
.NET Core RC2 will soon be showing up in the Red Hat Enterprise Linux software collection. You will be able to install it with yum, following instructions which will soon be posted to the redhatloves.net site.
Ubuntu was the first distro that we supported. We heard feedback that it made more sense to start with Debian, given that it is the parent of Ubuntu and many more distros. More recently, we added support for Debian, enabling .NET Core to be used in a larger set of Debian-based distros.
We intend .NET Core to be an open and flexible development platform. We’ll publish instructions in the next couple weeks on how to test .NET Core on arbitrary distros. You can see how Linux Mint is supported in runtimes.json, for example.

 

How to Install ASP.NET Core RC2

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

Uninstall ASP.NET Core RC1

The RC2 installer doesn’t override previous installation. So if you already have ASP.NET Core RC1 installed then you have to manually uninstall it and then install ASP.NET Core RC2.

Download the tooling and install it

So first let’s download and install tooling. With RC2 release, Microsoft has also put all the .NET Core related stuff on a new website dot.net (You can say dotdotnet. Though dotnet.net would have been good choice). 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.

 

So once downloaded, run the installer and this should install tooling on your system.

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

Create your first .NET Core application

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


and you should see 1.0.0-preview1-002702 as output.




So let’s create a new app. So execute following commands.


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

Download the ASP.NET Core RC2 and install it

When you install tooling, you won’t get the RC2 templates in Visual Studio 2015. And as of now, with dotnet-cli you can’t create ASP.NET Core application. So download Visual Studio 2015 MSI installer from here. Note, the Visual Studio MSI installer requires that you should have Visual Studio 2015 Update 2 installed. So make sure to update your Visual Studio 2015 to Update 2. You can download Update 2 from here. If you don’t have Visual Studio already, you can download Visual Studio Community 2015 for free.
Once downloaded, run the Visual Studio MSI installer. You should see following setup screen.


And it will take sometime to finish. Okay, so all set now to create your first ASP.NET Core RC2 application.

Create your first ASP.NET Core RC2 application

With RC2, you will see separate templates for ASP.NET and ASP.NET Core project. Till RC1, this was not present. 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.


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


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

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

I already covered the changes in my post about web.config, new program.cs file and project.json changes. So I recommend you to read the post for all changes in RC2.
Hit F5 and run the application. And you should see your application running with default ASP.NET Core template. Let’s modify code to display a welcome message on the screen. So open HomeController from the Controllers folder and modify the Index() action as follows:


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 :



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