Build and launch an ASP.NET Core app from Google Cloud Shell

1. Overview

ASP.NET Core is a new open-source and cross-platform framework for building modern cloud-based and internet-connected applications using the C# programming language.

Google Cloud Shell is a browser-based command line tool to access Google Cloud Platform resources. Cloud Shell makes it really easy to manage your Cloud Platform Console projects and resources without having to install the Google Cloud SDK and other tools on your system. With Cloud Shell, the Cloud SDK gcloud command and other utilities such as .NET Core command line interface tools are always available when you need them.

In this lab, you will learn about how to build and launch an ASP.NET Core app from Google Cloud Shell — without ever leaving the browser.

What you'll learn

  • Google Cloud Shell
  • ASP.NET Core basics
  • How to create a simple ASP.NET Core app inside Google Cloud Shell
  • How to launch the ASP.NET Core app from Google Cloud Shell

What you'll need

  • A Google Cloud Platform Project
  • A browser, such Chrome or Firefox

How will you use this tutorial?

Read it through only Read it and complete the exercises

How would rate your experience with Google Cloud Platform?

Novice Intermediate Proficient

2. Setup and requirements

Self-paced environment setup

If you don't already have a Google account (Gmail or GSuite), you must create one. Then, sign-in to Google Cloud Platform console ( console.cloud.google.com) and create a new project:

aa2b71cbc7c28c59.png

19eb08d9ea73f0ea.png

Remember the project ID, a unique name across all Google Cloud Platform projects. It will be referred to later in this codelab as PROJECT_ID.

Next, you'll need to enable billing in Google Cloud Console in order to use Google Cloud Platform resources.

Start Cloud Shell

Google Cloud Shell is the browser-based command line tool to access Google Cloud Platform resources. Cloud Shell makes it really easy to manage your Cloud Platform Console projects and resources without having to install the Google Cloud SDK and other tools on your system. With Cloud Shell, the Cloud SDK gcloud command and other utilities such as .NET Core command line interface tools are always available when you need them.

To get started:

  1. Visit the Google Cloud Platform Console
  2. Click on the "Activate Google Cloud Shell" icon in top right hand corner of the header bar

toolbar-cloudshell.png

A Cloud Shell session opens inside a new frame at the bottom of the console and displays a command-line prompt. This might take a few seconds as Cloud Shell is spinning a VM.

60fba3df157aec3a.png

Wait until the $ prompt appears.

3. Understanding ASP.NET Core

ASP.NET Core is a significant redesign of the traditional Windows-only ASP.NET framework. You can develop and run your ASP.NET Core apps cross-platform on Windows, Mac and Linux.

ASP.NET Core comes with the .NET Core command-line interface (CLI), a new foundational cross-platform toolchain for developing .NET Core applications. This toolchain is already installed in Google Cloud Shell.

In the next section, we use the .NET Core command-line interface to create our first ASP.NET Core app.

4. Create an ASP.NET Core app in Cloud Shell

In Cloud Shell prompt, you can verify that the dotnet command line tool is already installed by checking its version. This should print the version of the installed dotnet command line tool:

dotnet --version

Next, create a new skeleton ASP.NET Core web app.

dotnet new mvc -o HelloWorldAspNetCore

This should create a project and restore its dependencies. You should see a message similar to below.

Restore completed in 11.44 sec for HelloWorldAspNetCore.csproj.

Restore succeeded.

5. Run the ASP.NET Core app

We're almost ready to run our app. Navigate to the app folder.

cd HelloWorldAspNetCore

Finally, run the app.

dotnet run --urls=http://localhost:8080

Application starts listening on port 8080.

Hosting environment: Production
Content root path: /home/atameldev/HelloWorldAspNetCore
Now listening on: http://[::]:8080
Application started. Press Ctrl+C to shut down.

To verify that the app is running, click on the web preview button on the top right and select ‘Preview on port 8080'.

Capture.PNG

You'll see the default ASP.NET Core webpage:

wPlsc5EzDpwH0en46xxV3vQZV2LupOqGs4h9y2D7iyWMqNo7tv4_1FAoqTQP6BIhH81i2ZXrsw8Bn2PmFbyA9pHy6zy_zabyzdUFUPkcXeomvSbtwQDgd6arZQRQUpzpbXHD14MNWA

Once you verify that the app is running, press Ctrl+C to shut down the app.

6. Congratulations!

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.

What we've covered

  • Google Cloud Shell
  • ASP.NET Core basics
  • How to create a simple ASP.NET Core app inside Google Cloud Shell
  • How to edit the ASP.NET Core app using Eclipse Orion
  • How to launch ASP.NET Core app from Google Cloud Shell

Next Steps