Jump to Content
Google Cloud

How to build and launch an ASP.NET Core app from Google Cloud Shell — without ever leaving the browser

November 10, 2016
Mete Atamel

Cloud Developer Advocate

Google Cloud Shell, my favorite development tool for Google Cloud Platform, just got more awesome with two new features.

First, we recently integrated Eclipse Orion, an online code editor, with Cloud Shell. If you're not a Vim or Emacs fan, Orion is a welcome addition to Cloud Shell. It enables you to edit code right inside the browser with basic syntax highlighting and minimal effort.

Second, we added .NET Core command line interface tools to Cloud Shell. This is a new cross-platform toolchain for developing .NET Core applications and it can be used to create, run and publish .NET Core apps from the command line.

With these two new additions, you can easily create an ASP.NET Core web app in Cloud Shell, edit it using Orion and run it on a Linux instance (yes, ASP.NET Core apps run on Linux!) right inside your browser. Let's take a look at the steps involved.

Create an ASP.NET web app in Cloud Shell

From Google Cloud Console, click on the Cloud Shell icon on the top right section of the toolbar to activate Cloud Shell:

https://storage.googleapis.com/gweb-cloudblog-publish/images/ASP3bw3.max-300x300.PNG

And, create a folder for our HelloWorld app:

Loading...

Then, create a skeleton ASP.NET Core web app using the dotnet command:

Loading...

Use Orion to change the default port

By default, ASP.NET Core web apps run on port 5000. Let's change that to a more conventional port for web apps, port 8080.

Loading...

Open Orion by clicking Files and then Launch Code Editor at the top of Cloud Shell. Once the code editor is open, find Program.cs in the folder:

https://storage.googleapis.com/gweb-cloudblog-publish/images/ASP85js.max-700x700.PNG

Add the UseUrls line to bind to port 8080:

Run the ASP.NET web app

We're almost ready to run our app but we need to restore dependencies first. This will download all the NuGet dependencies for our app:

Loading...

Finally, run our app:

Loading...

At this point, our app is running on Linux! Don’t believe it? You can convince yourself by visiting the web preview and Preview on port 8080:

https://storage.googleapis.com/gweb-cloudblog-publish/images/ASPvmaa.max-400x400.PNG

You'll see the default ASP.NET Core webpage in a new tab.

Next steps

There! You’ve just created and launched an ASP.NET Core app from inside Cloud Shell, without once leaving your browser. But that’s not all you can do. You can take your newly created ASP.NET Core app, containerize it using Docker and deploy it to Google App Engine or you can let Kubernetes manage it all for you in Google Container Engine. It’s easy to see why Cloud Shell is my favorite GCP development tool.

Posted in