Analyze the Future

Google Cloud Platform

Most .NET developers think of Azure or AWS when considering cloud hosting.  Azure, backed by Microsoft has excellent tooling and hosting options for .NET developers.  AWS is an established cloud provider and the leader in the market.  Many developers don’t realize that Google Cloud Platform or GCP for short, is also an excellent cloud platform for running .NET applications.  Best of all, if you’re an ASP.NET developer, you don’t have to do anything different from what you’re use to.  You can still use Visual Studio to build your app and choose GCP as your deployment target.  Today, I’m going to explain how you would deploy an ASP.NET Core web application to Google App Engine Flex using Jetbrains Rider as your development Environment.

File New Solution

The first thing you do is open Jetbrains Rider and select New Solution->ASP.NET Core Web App (Model-View-Controller).  You’re not limited to Jetbrains Rider.  You can use VSCode to generate a new ASP.NET MVC Core app from the command line with the command: dotnet new mvc.  You can also use Visual Studio for Mac or Visual Studio for Windows.

File New Solution
File New Solution

Complete the wizard and Jetbrains Rider will create a new ASP.NET Core Web Application.


Make a change to the index.cshtml page

<div class=”panel-heading”>
<h1>Hello from Google App Engine Flex</h1>

Run the app and you’ll have a default ASP.NET Core app running in your browser.

Default ASPNET App Running

Preparing for App Engine Flex

In order to run your ASP.NET Core app on Google App Engine Flex you have to choose the App Engine Flexible Environment. Let’s prepare our ASP.NET Core app for App Engine Flexible.  Create an app.yaml file.  Add the following configurations:

runtime: aspnetcore
env: flex 

Next, modify your .csproj file.  Add the following:

<None Include="app.yaml" CopyToOutputDirectory="PreserveNewest" />

The next step is to deploy to Google App Engine but first we’ll have to create a GCP account at https://cloud.google.com/ and create a project.  Comment below if you would like to see a blog post on creating a project on Google Cloud Platform.  The next steps will be performed at the command line:

  1. Make sure you have the gcloud command line tools installed.  Comment below if you would like to see a blog post on installing the gcloud command line tools.
  2. Authenticate gcloud using this command: gcloud auth login.  Follow the instructions and gcloud will be granted permissions on your behalf.
  3. Run the project one more time to ensure the project still works after the addition of the app.yaml and the modification to your .csproj file.
  4. Within your terminal window, ensure you’re in the root directory where your app.yaml file is located and run the following command to create a release: dotnet publish -c Release.
  5. The previous command will create a release package in your bin/Release/netcoreapp2.0/publish/ directory.
  6. In your terminal window navigate to bin/Release/netcoreapp2.0/publish/ and run the following commands to set gcloud to the default GCP project:
    1. gcloud config set project <project-name>
    2. gcloud app deploy
  7. gcloud app deploy will deploy your ASP.NET Core project to App Engine Flexible.  You’ll need to choose the region where you want your app deployed.  It’s best to choose a region closer to where you expect your users will use your app.
  8. gcloud will then create an app engine project and then ask you to confirm whether you want to continue.  Choose ‘Y’.

If this is your first deployment, it will take a few minutes before your application is deployed to App Engine Flex.

When gcloud has successfully deployed your app, run the following command from your terminal: gcloud app browse.  You’ll see your app running on App Engine Flex in your default browser with an app engine URL. For example https://your-project-id.appspot.com.

Running on Google App Engine Flex

Running on App Engine Flex isn’t free so you should delete the project in order not to incur charges for your project.  In a future blog post I’ll demonstrate how you can save money running your applications on Google App Engine Flexible.  Please share this blog post with any .NET engineer wanting to get started with Google Cloud Platform.  Comment below if you have questions.

Related Post

Leave a Comment