The .NET Runtime
Overview
Your Cloud Run function runs in an environment consisting of an operating system version plus add-on packages, language support, and the Functions Framework library that supports and invokes your function. This environment is identified by the language version, and is known as the runtime.
For information about runtimes in general, and to learn which Ubuntu version each .NET runtime uses, see the Cloud Run functions execution environment.
To get started with .NET on Cloud Run functions, see the Quickstart.
Template package
The template package helps you to create new functions. To use it:
Install the .NET SDK.
Install the template package:
dotnet new install Google.Cloud.Functions.Templates
Templates are provided for the three kinds of functions in C# (the default), F#,
and Visual Basic. When creating a new project from a template, specify
-lang f#
to create an F# project, or -lang vb
to create a Visual Basic
project. For more information, see:
- Your First Function: C#
- .NET Languages (for F# and Visual Basic)
Select a .NET Functions Framework version
Different versions of the .NET Functions Framework support different runtimes. Version 1 supports .NET Core 3.1 and later, with templates defaulting to .NET Core 3.1. Version 2 supports .NET 6 and later, with templates defaulting to .NET 6.
To upgrade an existing project using .NET Functions Framework version 1,
edit the project file (or use Visual Studio) to update all dependencies that
begin with Google.Cloud.Functions
to the latest version, and set the
target framework to .NET 6.
Select your runtime
Cloud Run functions supports several versions of .NET, listed on the
Runtime support page. When you deploy
your function, you must specify
a .NET runtime corresponding to the target framework in your project file
(MyFunction.csproj
or similar). To specify your .NET runtime:
gcloud
If you're using the Google Cloud CLI, specify the runtime
by using the --runtime
parameter. The --entry-point
flag specifies the
fully qualified class name (FQN). For example:
gcloud functions deploy NAME --entry-point FQN --runtime dotnet8 --trigger-http FLAGS...
FLAGS...
refers to arguments passed during the first
deployment of your function. For more information regarding required and
optional arguments, see
Deploy using the Google Cloud CLI.
Console
If you're using the Google Cloud console, see the Google Cloud console quickstart for detailed instructions.
Function preparation
You can prepare a function directly from the Google Cloud console or write it on your local machine and upload it. To prepare your local machine for .NET development, see Setting up a .NET development environment.
The library that invokes your function is the .NET Functions Framework.
To get started quickly with .NET on Cloud Run functions, see the Quickstart.
Source code structure
In order for Cloud Run functions to find your function's definition, each runtime has certain structuring requirements for your source code. See Write Cloud Run functions for more information.
Specifying dependencies
You can specify dependencies for your function by adding them to a project file. For more information, see Specifying dependencies in .NET.
What's next
- Create your first C# function from scratch.
- Learn about the other .NET languages you can use to write Cloud Run functions: F# and Visual Basic.