How to Deploy .NET 5.0 to Cloud Run

How to Deploy .NET 5.0 to Cloud Run

.NET 5.0 was released just a few days ago with many new features and improvements. In this blog post, we show you how to deploy .NET 5.0 to Cloud Run

.NET 5.0 was released just a few days ago with many new features and improvements. In this blog post, we show you how to deploy .NET 5.0 to Cloud Run

A unified .NET

.NET 5.0 was released just a few days ago with many new features, improvements, C## 9 support, F## 5 support, and more. .NET 5.0 is the first release of the unified .NET vision that was announced last year. Going forward, there will be just one .NET targeting Windows, Linux, macOS, and more.

Google Cloud already has support for different versions of .NET. You can run traditional Windows based .NET apps on Windows Servers in Compute Engine or on Windows Containers in Google Kubernetes Engine (GKE). For modern Linux based containerized .NET apps, there’s more choice with App Engine (Flex), GKE and my favorite Cloud Run. Not to mention, the .NET Core 3.1 support in Cloud Functions is currently in preview for serverless .NET functions.

In the rest of the blog post, I want to show you how to deploy .NET 5.0 to Cloud Run. Cloud Run makes it really easy to deploy and scale containerized apps on a fully managed platform.

.NET 5.0

First, make sure you have the latest .NET 5.0 installed:

> dotnet --version


Let’s follow the ASP.NET tutorial to create a web app with ASP.NET framework. Create a simple web app with plain HTTP support:

> dotnet new webapp -o webapp-cloudrun --no-https

Cloud Run expects for the app to listen on a PORT environment variable. Change CreateHostBuilder function of Program.cs file to do that:

  public static IHostBuilder CreateHostBuilder(string[] args)
  var port = Environment.GetEnvironmentVariable("PORT") ?? "8080";
  var url = $"{port}";

  return Host.CreateDefaultBuilder(args)
    .ConfigureWebHostDefaults(webBuilder =>

Also, let’s change the default welcome message in Index.cshtml file to display a welcome message like this:

<h1 class="display-4">Welcome to .NET 5.0 on Google Cloud</h1>

After the changes, you can build and run the app locally. It should start a server listening on port 8080:

> dotnet run

info: Microsoft.Hosting.Lifetime[0]

 ` Now listening on:`

Containerize .NET 5.0

To containerize the app, we will create a Dockerfile. One thing to keep in mind is that with the release of .NET 5.0, all Docker tags for .NET Core 2.1/3.1 and .NET 5.0 is published to one set of unified Docker repositories (see 2375). The names of these repositories have been changed from the originals to no longer include "core" in the name.

Here’s the Dockerfile for our app using the new dotnet/sdk and dotnet/aspnet base images with 5.0 versions:

FROM AS build


COPY *.csproj ./

RUN dotnet restore

COPY . ./


RUN dotnet publish -c Release -o out

FROM AS runtime


COPY --from=build /app/out ./

ENTRYPOINT ["dotnet", "webapp-cloudrun.dll"]

Build and save the Docker image to Google Container Registry with Cloud Build:

> gcloud builds submit --tag${GOOGLE_CLOUD_PROJECT}/hello-dotnet5

Deploy to Cloud Run

Finally, deploy to Cloud Run:

> gcloud run deploy --image${GOOGLE_CLOUD_PROJECT}/hello-dotnet5 \

    `--platform managed \`


In a few seconds, you should see the service deployed:

✓ Deploying... Done.

✓ Creating Revision...

✓ Routing traffic...

✓ Setting IAM Policy...


Service [hello-dotnet5] revision [hello-dotnet5-00002-tux] has been deployed and is serving 100 percent of traffic.

Service URL:

And visiting the service URL will display our page:


Of course .NET support is not limited to Cloud Run. Check out how we support .NET on Google Cloud.

The Original Article can be found on

dotnet cloud developer

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Multi-cloud Spending: 8 Tips To Lower Cost

Mismanagement of multi-cloud expense costs an arm and leg to business and its management has become a major pain point. Here we break down some crucial tips to take some of the management challenges off your plate and help you optimize your cloud spend.

Best Cloud Computing (AWS) Development Company

Develop highly scalable apps on Amazon Cloud Services in India. Mobile App Development India Offers Amazon cloud web services (AWS) for app development, database storage solution, hosting solution etc.

What are the benefits of cloud migration? Reasons you should migrate

To move or not to move? Benefits are multifold when you are migrating to the cloud. Get the correct information to make your decision, with our cloud engineering expertise.

How long does it take to develop/build an app?

This article covers A-Z about the mobile and web app development process and answers your question on how long does it take to develop/build an app.

Developer Career Path: To Become a Team Lead or Stay a Developer?

For a developer, becoming a team leader can be a trap or open up opportunities for creating software. Two years ago, when I was a developer, ... by Oleg Sklyarov, Fullstack Developer at Skyeng company