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 Cloud Platform Console to create a new Cloud Platform 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, to build and run .NET core applications you must install .NET Core tools.
      • GA images are available for ASP.NET Core apps written for .NET Core 1.0 and 1.1 and a preview image for ASP.NET Core apps written for .NET Core 2.0-preview1.
    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 Cloud Platform products and services that are utilized 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
  • us-east1
  • us-east4
  • europe-west1
  • europe-west2
  • europe-west3
  • asia-northeast1
  • australia-southeast1
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 beta 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 Cloud Platform 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

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

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.

Send feedback about...

App Engine flexible environment for .NET docs