The .NET Runtime


The .NET runtime is the software stack responsible for installing your application code and its dependencies and running your application. The flexible runtime is declared in your app.yaml file:

runtime: aspnetcore
env: flex

Runtimes in the flexible environment are built using Docker.

Google Cloud Tools for Visual Studio creates an app.yaml file and a Dockerfile in the build output directory if these files don't already exist in your project.

If you want to use Container Engine or other Docker hosts, you need to create a Dockerfile based on this image that copies your application code and installs dependencies. For example:

COPY . /app
ENTRYPOINT ["dotnet", "Metadata.dll"]

HTTPS and forwarding proxies

App Engine terminates the HTTPS connection at the load balancer and forwards the request to your application. Applications can examine the X-Forwarded-Proto to observe whether the original protocol was HTTP or HTTPS.

Some applications also need to ascertain the user's IP address. This is available in the standard X-Forwarded-For header.

Extending the runtime

The flexible environment .NET runtime can be used to create a custom runtime. Custom runtimes are configured via a Dockerfile.

You can customize the Dockerfile and .dockerignore as desired. Finally, you will need to specify runtime: custom instead of runtime: aspnetcore in app.yaml. See Customizing the .NET Runtime for more information.

Environment variables

The following environment variables are set by the runtime environment:

Environment variable Description
GAE_INSTANCE The name of the current instance.
GAE_MEMORY_MB The amount of memory available to the application process.
GAE_SERVICE The service name specified in your application's app.yaml file, or if no service name is specified, it is set to default.
GAE_VERSION The version label of the current application.
GCLOUD_PROJECT The Project ID associated with your application, which is visible in the Google Cloud Platform Console
PORT The port that will receive HTTP requests.

You can set additional configuration variables with appsettings.json.

Metadata server

Each instance of your application can use the Compute Engine metadata server to query information about the instance, including its host name, external IP address, instance ID, custom metadata, and service account information. App Engine does not allow you to set custom metadata for each instance, but you can set project-wide custom metadata and read it from your App Engine and Compute Engine instances.

This example function uses the metadata server to get the external IP address of the instance:

/// <summary>
/// Query the metadata server to find my ip address.
/// </summary>
/// <returns>My ip address, or null if not running on Google Cloud.</returns>
async Task<string> GetMyGoogleCloudIpAddressAsync()
    var metadataClient = Google.Cloud.Metadata.V1.MetadataClient.Create();
        var result = await metadataClient.GetMetadataAsync(
        return result.Content.ToString();
    catch (System.Net.Http.HttpRequestException)
        // Must not be running on App Engine.
    return null;

Send feedback about...

App Engine flexible environment for .NET docs