Skip to main content
All docs
V26.1
  • Google Cloud Run — Deploy an ASP.NET Core Reporting App with the CLI

    • 5 minutes to read

    Use the .NET CLI to create a sample ASP.NET Core DevExpress Reporting application that includes the Document Viewer and Report Designer, and deploy it to Google Cloud Run with the Google Cloud CLI.

    Prerequisites

    1. A Google Cloud account with an active subscription.
    2. A Cloud Billing account.
    3. The latest version of Google Cloud CLI.
    4. DevExpress ASP.NET Core CLI Templates:

      dotnet new install DevExpress.AspNetCore.ProjectTemplates
      

    Important Disclaimer

    The deployment recommendations do not apply to all possible configurations and should not be considered comprehensive. We offer these instructions as a getting-started reference. Steps may vary depending on your operating system, installed software, and DevExpress versions. You, the developer, are responsible for the application, database, network, and other configurations based on your client, security, environment, and other requirements. We recommend that you review these settings with your database, network, and IT infrastructure administrators and consider tailoring their recommendations to your case.

    Create a Sample ASP.NET Core App with DevExpress Reports

    Run the following command to create a sample ASP.NET Core application with a Debian-based Docker image:

    dotnet new dx.aspnetcore.reporting -n dxreportingtestapp --framework net10.0 --Dockerfile Debian
    

    For information about available options, run:

    dotnet new dx.aspnetcore.reporting -h
    

    For more information about the ASP.NET Core Reporting project template, see Use DevExpress Templates.

    Initialize the Google Cloud CLI

    1. In the application directory, run the following command to log in to your Google Cloud account:

      cd dxreportingtestapp
      gcloud init
      

      For additional information, see Initialize the gcloud CLI.

    Create and Configure a Google Cloud Project

    1. Create a project and set it as active:

      gcloud projects create <PROJECT_ID>
      gcloud config set project <PROJECT_ID>
      

      Where <PROJECT_ID> is a globally unique project identifier (lowercase letters, numbers, and hyphens).

    2. Link the project to your billing account.

      Refer to the following articles for additional information:

    3. Enable required APIs:

      gcloud services enable run.googleapis.com cloudbuild.googleapis.com secretmanager.googleapis.com artifactregistry.googleapis.com
      

      For additional information, see Enable and disable services.

    4. Find the Compute Engine default service account:

      gcloud iam service-accounts list
      

      Copy the email in the format <PROJECT_NUMBER>-compute@developer.gserviceaccount.com. Use it as <SERVICE_ACCOUNT_EMAIL> in the next step.

    5. Grant the required roles to the service account:

      gcloud projects add-iam-policy-binding <PROJECT_ID> --member="serviceAccount:<SERVICE_ACCOUNT_EMAIL>" --role="roles/run.builder"
      gcloud projects add-iam-policy-binding <PROJECT_ID> --member="serviceAccount:<SERVICE_ACCOUNT_EMAIL>" --role="roles/storage.objectViewer"
      gcloud projects add-iam-policy-binding <PROJECT_ID> --member="serviceAccount:<SERVICE_ACCOUNT_EMAIL>" --role="roles/artifactregistry.writer"
      gcloud projects add-iam-policy-binding <PROJECT_ID> --member="serviceAccount:<SERVICE_ACCOUNT_EMAIL>" --role="roles/secretmanager.secretAccessor"
      
    6. Create a NuGet.config file in the project root.

      This file overrides NuGet package sources because Cloud Build does not have access to your system-level NuGet config:

      <?xml version="1.0" encoding="utf-8"?>
      <configuration>
        <packageSources>
          <clear />
          <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
        </packageSources>
        <fallbackPackageFolders>
          <clear />
        </fallbackPackageFolders>
      </configuration>
      

      DevExpress packages are available on nuget.org. This single source is sufficient to restore DevExpress packages in the cloud.

    Pass the DevExpress License Key to the Build Pipeline

    Google Cloud Build runs in a remote environment that does not have access to your local DevExpress installation. Use Google Secret Manager to securely pass your license key to the Docker build.

    1. Create a secret (DEVEXPRESS_LICENSE):

      gcloud secrets create DEVEXPRESS_LICENSE --replication-policy="automatic"
      
    2. Upload your local license file to the secret (run this command from PowerShell):

      gcloud secrets versions add DEVEXPRESS_LICENSE --data-file="$env:APPDATA/DevExpress/DevExpress_License.txt"
      

      This command works only on a development machine where DevExpress is installed in the default location. Update --data-file if your license file is stored elsewhere.

    3. Create a build configuration file (cloudbuild.yaml) in the project root.

      This file defines the Cloud Build steps that retrieve the secret and pass it to the Docker build:

      steps:
        - name: gcr.io/cloud-builders/gcloud
          entrypoint: bash
          args:
            - -c
            - |
              gcloud secrets versions access latest \
                --secret=DEVEXPRESS_LICENSE > DevExpress_License.txt
      
        - name: 'gcr.io/cloud-builders/docker'
          env:
            - 'DOCKER_BUILDKIT=1'
          args:
            - build
            - --secret=id=DEVEXPRESS_LICENSE,src=DevExpress_License.txt
            - -t
            - <IMAGE_PATH>
            - .
      images:
        - <IMAGE_PATH>
      

      Refer to Prepare a Docker Image below for guidance on how to set <IMAGE_PATH> to the full path of your Docker image in Artifact Registry.

    4. Update the Dockerfile to read the secret and copy the license file during the build stage.

      Replace the dotnet build line in the generated Dockerfile with the following:

      # RUN dotnet build "dxreportingtestapp.csproj" -c Release -o /app/build
      # Pass the license key as a secret and copy it before building
      RUN --mount=type=secret,id=DEVEXPRESS_LICENSE \
          mkdir -p $HOME/.config/DevExpress && \
          cp /run/secrets/DEVEXPRESS_LICENSE $HOME/.config/DevExpress/DevExpress_License.txt && \
          dotnet build "dxreportingtestapp.csproj" -c Release -o /app/build
      

    Prepare a Docker Image

    1. Create a .gcloudignore file in the project root to control which files Cloud Build receives. Exclude build artifacts, IDE files, and secrets:

      bin/
      obj/
      **/bin/
      **/obj/
      *.user
      *.suo
      .vscode/
      .vs/
      secrets.*
      appsettings.*.json
      !appsettings.json
      .nuget/
      packages/
      node_modules/
      *.bak
      
    2. Create an Artifact Registry repository:

      gcloud artifacts repositories create <REPOSITORY_NAME> --repository-format=docker --location=<LOCATION> --description="Docker images"
      

      Where:

      • <REPOSITORY_NAME> — Artifact Registry repository name.
      • <LOCATION> — Google Cloud region (for example, us-central1 or europe-west1). Use the same region in subsequent steps.
    3. Authenticate Docker with Artifact Registry:

      gcloud auth configure-docker <LOCATION>-docker.pkg.dev
      
    4. Set the image path. In cloudbuild.yaml, replace <IMAGE_PATH> with the following:

      <LOCATION>-docker.pkg.dev/<PROJECT_ID>/<REPOSITORY_NAME>/<IMAGE_NAME>
      
    5. Use Cloud Build to build and push the Docker image:

      gcloud builds submit --config cloudbuild.yaml
      

    Deploy to Google Cloud Run

    1. Deploy the built image to Cloud Run:

      gcloud run deploy <SERVICE_NAME> \
      --image=<IMAGE_PATH> \
      --platform=managed \
      --region=<LOCATION> \
      --allow-unauthenticated
      

      Note

      --allow-unauthenticated makes the service publicly accessible and is used here for demonstration purposes only.

      Where:

      • <SERVICE_NAME> — Cloud Run service name displayed in the Cloud Run console.
      • <LOCATION> — Cloud Run region (should match the Artifact Registry region).
      • <IMAGE_PATH> — Full Docker image path from Artifact Registry (same as used in cloudbuild.yaml).
    2. After successful deployment, the Google Cloud console displays the public URL of your service.