Announcing .NET Core 2.0 Support for OpenShift

.NET Core 2.0 now on OpenShift!

We at Red Hat are very happy to announce support for .NET Core 2.0 on OpenShift! This will allow you to containerize the latest in C# ASP.NET projects as you’re working with them in Visual Studio 2017 for Windows or Visual Studio Code for Linux, Mac, and Windows.

Here are URLs to use:

  • .NET Core 2.0 source-to-image builder:
  • .NET Core 2.0 runtime image:

Do not use http:// in front of these URLs.

With these, you can create your .NET Core 2.0 project in OpenShift using the command line interface (CLI).

What To Do Next

If you’re not sure how to work with these for creating your ASP.NET containers, here’s a quick run-down of what to do on OpenShift Online:

Step 1

First, make sure that you’re registered for OpenShift Online. Sign up is quick and easy with your Red Hat account, or OAuth supported through GitHub and many other social accounts.

Step 2

Create your project as usual, and afterwards, click on the ? icon (in the upper-right corner, next to your username) and select Command Line Tools. This will give you instructions on how to login to your cluster through the CLI, with the command oc login [URL] --token=. Copying and pasting this line into your command prompt will log you in if you have OC Tools installed (files and instructions for OC Tools will be on the same page). To get a token another way, you can initially visit http://[URL from project]/oauth/token/request to receive your unique token. Keep this secret, as it’s tied to your account and just for your use. Copy the line from that to the CLI to login.

Step 3

Once in, you can use a Git repo to upload a .NET Core 2.0 app using the image stream (IS). Simply use oc new-app [IS URL]~[repo URL]. Once done with that, your app should be showing up in the web console Overview for your project in OpenShift Online! You can continue working with it from there or from the CLI.

As always, this S2I can also be used to run your containers on OpenShift Dedicated and OpenShift Origin as well! Also, watch for .NET Core 2.0 to be added to the language catalog in the near future, to make it even easier to add to your projects through the web GUI.

Something Else to Try

Don’t have your own project to try out yet? I made a quick example ASP.NET app using .NET Core 2.0 to show you how it works! Here’s a rundown of how to do it in Visual Studio. If you’d like to skip making your own project and just use an example that we made, then head to the OpenShift Evangelists GitHub and copy the link for the .git.

Step 1

Open up your copy of one of the Visual Studio 2017 IDEs (as mentioned above, Community and Code editions are free to download). I’m using Community 2017 here because it has Workloads that make these projects a snap to create. Make sure that you have the framework for making a ASP.NET Core Web Application in C# installed. If you click “Create new project…” you should see a menu for Visual C# on the next screen, with a Web category that you can select below that. Make an ASP.NET Core Web Application and give it a unique name.

If you don’t have this option available yet, then instead see the Not finding what you’re looking for? Open Visual Studio Installer link on the lower left, below the Installed categories. From there, select the ASP.NET and web development Workload from the Web & Cloud category.

Step 2

On the following screen, make sure that .NET Core and ASP.NET Core 2.0 are selected in the drop down menus at the top and that Web Application is also selected. Click OK.

This project now has everything that you need just to run it and test that it works. However, we can add some quick personalization to it, just so that you can see your own work in action. From the Solution Explorer on the right side of Visual Studio (in the default view), select [project name] -> Pages -> Index.cshtml. You’ll see some HTML code in here. You can add your own message near the top, under this code (although you probably shouldn’t use <BIG>¬†tags like I did):

@model IndexModel
ViewData["Title"] = "Home page";

Step 3

Save your solution, and create a repo, such as with GitHub. Now, you’ll have to make a few changes to the file hierarchy to get this working correctly with Git. If your Visual Studio project is named “example” (for example), then you would need to navigate to clone or create your Git repo, and organize it like this on Windows:

  • Move your example.sln file and .vs directory into the same directory with your other files.
  • Most importantly, make sure that these are in the directory with example.csproj. This file is crucial to running your app on OpenShift.
  • Make sure that your .git directory is also in this same directory. This should be the “root” of your repo files.

Your files should then look something like the below image. Commit this to your Git repo.

Step 4

Login to your OpenShift cluster with oc login per the previous set of instructions. Create a new app using (surprise!) oc new-app, like this: oc new-app[your Git repo URL] (or to use my example, oc new-app

Step 5

Navigate to the web console in your browser, or use oc status in the CLI to see how your build is doing! Once it’s done, you can create a route to it by clicking the link in the Overview of the web console, and then follow the link to see your ASP.NET app displaying web pages (and whatever custom message that you added into there). How about that?

For More Information

For more on how Red Hat is supporting the release of .NET Core 2.0, take a look at RedHatLoves.NET for Red Hat Developer Program’s .NET topics, and Red Hat’s .NET Core 2.0 press release.

Please share with us what you’re going to be doing with ASP.NET in OpenShift, and let us know what topics you’d like to see in future .NET blogs! You can also check out all OpenShift blogs on .NET, and watch for more to come!

.NET, News, OpenShift Container Platform, OpenShift Dedicated, OpenShift Online
, , ,