How to run Hello World with .NET

This tutorial describes how to use Visual Studio to deploy an ASP.NET Framework-based Hello World app from a Windows development environment to a Compute Engine instance running Windows Server 2016.

This tutorial assumes that you have Visual Studio 2017 IDE for Windows or later installed and are familiar with the .NET Framework and the C# language.

You may also want to review our Quickstart for .NET in the App Engine Flexible Environment for the following reasons:

  • You want to deploy an ASP.NET Core-based Hello World app.
  • You want to deploy an app to the Beta App Engine Flexible environment, which provides automatic up and down scaling, as well as load balancing.
  • You want to deploy a Hello World app from the command line without using Visual Studio.

This is part of the Getting Started with .NET on GCP series . After you complete the prerequisites listed under Before you begin, the tutorial takes about 15 minutes to complete.

Before you begin

Check off each step as you complete it.

  1. check_box_outline_blank check_box Create a project in the Google Cloud Platform Console.
    If you haven't already created a project, create one now. Projects enable you to manage all Google Cloud Platform resources for your app, including deployment, access control, billing, and services.
    1. Open the GCP Console.
    2. In the drop-down menu at the top, select Create a project.
    3. Click Show advanced options.
    4. Give your project a name.
    5. Make a note of the project ID, which might be different from the project name. The project ID is used in commands and in configurations.
  2. check_box_outline_blank check_box Enable billing for your project, and sign up for a free trial.

    If you haven't already enabled billing for your project, enable billing now, and sign up for a free trial. Enabling billing allows the app to consume billable resources such as running instances and storing data. During your free trial period, you won't be billed for any services.

Download and run the app

We've created a simple Hello World app using .NET so you can quickly get a feel for deploying an app to Google Cloud Platform (GCP. After you've completed the prerequisites, you can download and deploy the Hello World sample app. This section guides you through getting the code and running the app locally.

Get the Hello World app

Download the sample as a zip file and extract it.

Alternatively, you can clone the git repository.

$ git clone

Run the app on your local computer

  1. To open the app in Visual Studio 2017, double-click aspnet\1-hello-world\1-hello-world.sln.

  2. In Visual Studio, press F5 to build and run the app.

You can see the Hello, World! message from the sample app displayed in the page. This page is delivered by a web server running on your computer.

When you are ready to move forward, press Shift-F5 to stop the app.

Hello World code review

The code is a simple ASP.NET app.

        /// <summary>
        /// The simplest possible HTTP Handler that just returns "Hello World."
        /// </summary>
        public class HelloWorldHandler : HttpMessageHandler
            protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,
                CancellationToken cancellationToken)
                return Task.FromResult(new HttpResponseMessage()
                    Content = new ByteArrayContent(Encoding.UTF8.GetBytes("Hello World."))

        public static void Register(HttpConfiguration config)
            var emptyDictionary = new HttpRouteValueDictionary();
            // Add our one HttpMessageHandler to the root path.
            config.Routes.MapHttpRoute("index", "", emptyDictionary, emptyDictionary,
                new HelloWorldHandler());

Running Hello World on GCP

Create and configure a new Compute Engine instance

First, use Google Cloud Platform Marketplace to create a new Compute Engine instance that has Windows Server 2016, Microsoft IIS, ASP.NET, and SQL Express preinstalled.

  1. In the GCP Console, go to the GCP Marketplace ASP.NET Framework page.

  2. Set your deployment name and preferred Compute Engine zone.

  3. To deploy the Compute Engine instance, click Deploy.

Install Cloud Tools for Visual Studio

To install Cloud Tools for Visual Studio, complete the following installation process:

  1. In Visual Studio, go to Tools > Extensions and Updates.

  2. In the left pane, click the Online tab from the left pane.

  3. Search for Google Cloud.

    Extensions and Updates dialog

  4. Click Download and follow the prompts.

  5. To load the new extension, restart Visual Studio.

Configure the Cloud Tools for Visual Studio to use your account

  1. In Visual Studio, launch Cloud Explorer by going to Tools > Google Cloud Tools > Show Google Cloud Explorer.

  2. To access GCP resources, add your Google account. Click Select or Create Account.

  3. Click Add account.

    Manage Accounts

Add a default Windows user to your new Compute Engine instance

  1. In Cloud Explorer, select the newly created project and expand Compute Engine.

  2. Right-click the VM instance that you created with GCP Marketplace and select Manage Windows credentials.

    Manage Accounts

  3. Click Add credentials.

  4. Enter a username.

  5. Select Create a password for me and click Save.

  6. When prompted, Reset the password for [YOUR USERNAME] on the instance [INSTANCE YOU CREATED], click Reset.

  7. To close the Password window, click the Close button.

  8. To close the Windows Credentials window, click the Close button.

Deploy the app to your Windows instance

  1. In the Visual Studio Solution Explorer pane, right-click your app and click Publish to Google Cloud.

    Publish to Google Cloud

  2. In the Publish dialog box, click Compute Engine.

    Choose to publish to Compute Engine

  3. To build and deploy the sample app, click Publish. After publishing completes, Visual Studio opens the app in your default web browser.

    Test application

Congratulations! You now have a working ASP.NET app running on a Compute Engine instance.

Cleaning up

If you're done with the tutorials and want to clean up resources that you've allocated, see Cleaning Up.

Var denne side nyttig? Giv os en anmeldelse af den: