Setting Up Stackdriver Debugger for .NET Core

This page describes how to configure your environment and your .NET Core application to use Stackdriver Debugger. For some environments, you must explicitly specify the access scope to let the Stackdriver Debugger agent send data. We recommend setting the broadest possible access scope and then using Cloud Identity and Access Management to restrict access. In keeping with this best practice, set the access scope to be all Cloud APIs with the option cloud-platform.

Before You Begin

  • To use Stackdriver Debugger while running your application locally:

    • Set the GOOGLE_APPLICATION_CREDENTIALS environment variable with the proper credentials.
    • Add the STACKDRIVER_DEBUGGER_PROJECT environment variable with the project you would like Stackdriver Debugger to run against.
  • When building the .NET Core application, be sure to add and deploy PDB files with your code. For example:

    ...
    <PropertyGroup>
      <TargetFramework>netcoreapp2.0</TargetFramework>
      <DebugType>portable</DebugType>
    </PropertyGroup>
    ...
    
  • Note that when debugging a Release build, variables might be misnamed or missing.

App Engine standard environment

The Stackdriver Debugger agent for .NET Core isn't supported in App Engine standard environment.

App Engine flexible environment

  1. Change the runtime in your app.yaml to custom:

    runtime: custom
    env: flex
    
  2. Use a custom Dockerfile:

    FROM gcr.io/dotnet-debugger/aspnetcore:2.0
    COPY . /app
    WORKDIR /app
    # If you don't have source context delete the below line.
    # See 'Selecting Source Code Automatically' below for more information.
    COPY ./source-context.json /usr/share/dotnet-debugger/agent/
    ENTRYPOINT ["/usr/share/dotnet-debugger/start-debugger.sh", "dotnet", "APPLICATION.dll"]
    

    Where:

    • APPLICATION is the application you wish to run and debug.

The debugger is now ready for use with your application.

To have the Debug page in the GCP Console automatically display source code matching the deployed application, see Selecting Source Code Automatically.

Google Kubernetes Engine

  1. Create your cluster, with one of the following access scopes:
    • https://www.googleapis.com/auth/cloud-platform
    • https://www.googleapis.com/auth/cloud_debugger

    To create a cluster using gcloud, do the following:

    1. (Optional) Update gcloud to the latest version:
      gcloud components update
    2. Set your default project ID:
      gcloud config set project [PROJECT_ID]
    3. If you're working with zonal clusters, set your default compute zone:
      gcloud config set compute/zone [COMPUTE_ZONE]
    4. If you're working with regional clusters, set your default compute region:
      gcloud config set compute/region [COMPUTE_REGION]
    5. Issue the create command:
      gcloud container clusters create example-cluster-name --scopes https://www.googleapis.com/auth/cloud-platform

    For more detailed information on creating a cluster, see Creating a cluster.

  2. Use a custom Dockerfile:
    FROM gcr.io/dotnet-debugger/aspnetcore:2.0
    COPY . /app
    WORKDIR /app
    # If you don't have source context delete the below line.
    # See running locally below for more information.
    COPY ./source-context.json /usr/share/dotnet-debugger/agent/
    ENV STACKDRIVER_DEBUGGER_MODULE=MODULE
    ENV STACKDRIVER_DEBUGGER_VERSION=VERSION
    # If running locally uncomment and set the following:
    # ENV STACKDRIVER_DEBUGGER_PROJECT=PROJECT_ID
    # ENV GOOGLE_APPLICATION_CREDENTIALS=CREDENTIALS_FILE
    ENTRYPOINT ["/usr/share/dotnet-debugger/start-debugger.sh", "dotnet", "APPLICATION.dll"]
    

    Where:

    • MODULE is the name of the application. Together with version, it identifies the application in the GCP Console. Examples: MyApp, Backend, or Frontend.
    • VERSION is the application version (e.g., the build ID). The GCP Console displays the running application as MODULE - VERSION. Examples: v1.0, build_147, or v20160520.
    • PROJECT_ID is the GCP Console Project ID.
    • CREDENTIALS_FILE is the path to service account or credential JSON file.
    • APPLICATION is the entry point to the application.

The debugger is now ready for use with your application.

To have the Debug page in the GCP Console automatically display source code matching the deployed application, see Selecting Source Code Automatically.

Compute Engine

The Stackdriver Debugger agent for .NET Core isn't supported in Compute Engine environment.

Was this page helpful? Let us know how we did:

Send feedback about...

Stackdriver Debugger Documentation