Quickstart for .NET in the App Engine Flexible Environment

This quickstart shows you how to create a small App Engine application that displays a short message.

Before you begin

Before running and deploying this sample, take the following steps:

  1. Use the GCP Console to create a new GCP project, create an App Engine application, and enable billing:
    Go to App Engine

    When prompted, select the region where you want your App Engine application located and then enable billing.

  2. Install the following prerequisites locally:
    1. Download and install the Google Cloud SDK and then initialize the gcloud tool:
      Download the SDK
    2. Install the .NET Core SDK, LTS version.
    3. If you are using Visual Studio, you must be using version 2015 or later.
      • Images are available for ASP.NET Core apps written for .NET Core 1.0, 1.1, and 2.0.
    4. To deploy to App Engine directly from Visual Studio, install Google Cloud Tools for Visual Studio.

App Engine locations

App Engine is regional, which means the infrastructure that runs your apps is located in a specific region and is managed by Google to be redundantly available across all the zones within that region.

Meeting your latency, availability, or durability requirements are primary factors for selecting the region where your apps are run. You can generally select the region nearest to your app's users but you should consider the location of the other GCP products and services that are used by your app. Using services across multiple locations can affect your app's latency as well as pricing.

App Engine is available in the following regions:

  • us-central1 (Iowa)
  • us-east1 (South Carolina)
  • us-east4 (Northern Virginia)
  • southamerica-east1 (São Paulo) *
  • europe-west1 (Belgium)
  • europe-west2 (London)
  • europe-west3 (Frankfurt)
  • asia-northeast1 (Tokyo)
  • asia-south1 (Mumbai)
  • australia-southeast1 (Sydney)

* For customers using the São Paulo region, all regional product SLAs remain in force. However, multi-region and cross-region functionality that span across North America and South America might temporarily have reduced availability or performance.

You cannot change an app's region after you set it.

If you already created an App Engine application, you can view the region by running the gcloud app describe command or opening the App Engine Dashboard in the GCP Console. The region of your App Engine application is listed under http://[YOUR_PROJECT_ID].appspot.com.

This quickstart assumes that you are familiar with building web applications with C#.

Download the Hello World app

We've created a simple Hello World app for .NET so you can quickly get a feel for deploying an app to the App Engine flexible environment. It's basically the same application you get when you use Visual Studio to create an empty ASP.NET core application, with an added app.yaml file. The app.yaml file is a App Engine configuration file that specifies your runtime and other App Engine specific settings.

  1. Download the sample app and extract it.

  2. If you're using the command line, navigate into the app directory, dotnet-docs-samples\appengine\flexible\HelloWorld.

Run Hello World on your local machine

Visual Studio

To run the Hello World app on your local computer:

  1. Open dotnet-docs-samples\appengine\flexible\HelloWorld\HelloWorld.sln with Visual Studio.
  2. Press F5.

    You can see the "Hello World" message from the sample app displayed in the page.

Command Line

To run the Hello World app on your local computer:

  1. Run the following commands from the dotnet-docs-samples\appengine\flexible\HelloWorld directory:
    dotnet restore
    dotnet run
  2. In your web browser, navigate to http://localhost:5000/

    You can see the "Hello World" message from the sample app displayed in the page.

  3. In your terminal window, press Ctrl+C to exit the web server.

Deploy and run Hello World on App Engine

Visual Studio

To deploy the Hello World app:

  1. Open dotnet-docs-samples\appengine\flexible\HelloWorld\HelloWorld.sln with Visual Studio.
  2. In Solution Explorer, right-click HelloWorld, and choose Publish to Google Cloud...
  3. Click App Engine Flex.
  4. Click Publish.
  5. Visit the following address in your browser to see your deployed app:
    https://YOUR_PROJECT_ID.appspot.com

Command Line

  1. Run the following commands from the dotnet-docs-samples\appengine\flexible\HelloWorld directory:
    dotnet restore
    dotnet publish -c Release
    gcloud app deploy .\bin\Release\netcoreapp1.0\publish\app.yaml
  2. Launch your browser and view the app at http://YOUR_PROJECT_ID.appspot.com, by running the following command:
    gcloud app browse
This time, the page that displays the Hello World message is delivered by a web server running on an App Engine instance.

Congratulations! You've deployed your first .NET app to App Engine flexible environment!

See the following sections for information about cleaning up as well as links to the possible next steps that you can take.

Clean up

To avoid incurring charges, you can delete your GCP project to stop billing for all the resources used within that project.

  1. In the Cloud Platform Console, go to the Projects page.

    Go to the Projects page

  2. In the project list, select the project you want to delete and click Delete project. After selecting the checkbox next to the project name, click
      Delete project
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

What's next

Learn the whole platform

Now that you know what it's like to develop and deploy App Engine apps, you can stretch out and see the rest of Google Cloud Platform. You already have the Google Cloud SDK installed and that gives you the tools to interact with products like Google Cloud SQL, Google Cloud Storage, Google Cloud Datastore, and more. For a guided walkthrough that teaches you how to create an application that uses the entire platform, not just App Engine, check out our quickstart on creating the Bookshelf app.

Learn about the App Engine flexible environment

Here are some topics to help continue your learning about App Engine.

Hello World code review

Hello World is the simplest possible App Engine app, as it contains only one service, has only one version, and all of the code is located within the app's root directory. This section describes each of the app files in detail.

Startup.cs

The Hello World app is a simple ASP.NET application:

    public class Startup
    {
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.Run(async (context) =>
            {
                await context.Response.WriteAsync("Hello World!");
            });
        }
    }

app.yaml

The app.yaml file describes an application's deployment configuration:

runtime: aspnetcore
env: flex

# This sample incurs costs to run on the App Engine flexible environment. 
# The settings below are to reduce costs during testing and are not appropriate
# for production use. For more information, see:
# https://cloud.google.com/appengine/docs/flexible/python/configuring-your-app-with-app-yaml
manual_scaling:
  instances: 1
resources:
  cpu: 1
  memory_gb: 0.5
  disk_size_gb: 10

Here, app.yaml specifies the runtime used by the app, and sets env: flex, specifying that the app uses the flexible environment.

Send feedback about...

App Engine flexible environment for .NET docs