How to build and launch an ASP.NET Core app from Google Cloud Shell — without ever leaving the browser
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:And, create a folder for our HelloWorld app:
Then, create a skeleton ASP.NET Core web app using the dotnet command:
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.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:
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:Finally, run our app:
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:
You'll see the default ASP.NET Core webpage in a new tab.