Analyze the Future
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.
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.
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> </div>
Run the app and you’ll have a default ASP.NET Core app running in your browser.
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:
<ItemGroup> <None Include="app.yaml" CopyToOutputDirectory="PreserveNewest" /> </ItemGroup>
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:
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 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.