The .NET Runtime
Your Cloud 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.
Cloud Functions supports the following .NET runtimes:
- .NET Core 6.0 (recommended)
- .NET Core 3.1 (only using Functions Framework v1)
For information about runtimes in general, and to learn which Ubuntu version each .NET runtime uses, see the Cloud Functions execution environment.
To get started with .NET on Cloud Functions, see the Quickstart.
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 above, with templates defaulting to .NET Core 3.1. Version 2 supports .NET 6 and above, with templates defaulting to .NET 6.
To upgrade an existing project using .NET Functions Framework version 1, simply
edit the project file (or use Visual Studio) to update all dependencies that
Google.Cloud.Functions to the latest version, and set the
target framework to .NET 6.
Select your runtime
You must specify a .NET runtime to run your function when you deploy it. This
runtime you select should correspond to the target framework in your project
MyFunction.csproj or similar). To specify your .NET runtime:
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 dotnet6 --trigger-http
For more deployment parameters, see Deploy using the gcloud tool.
If you're using the Google Cloud console, see the Google Cloud console quickstart for detailed instructions.
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 Functions, see the Quickstart.
Source code structure
In order for Cloud Functions to find your function's definition, each runtime has certain structuring requirements for your source code. See Write Cloud Functions for more information.
You can specify dependencies for your function by adding them to a project file. For more information, see Specifying dependencies in .NET.
- Create your first C# function from scratch.
- Learn about the other .NET languages you can use to write Cloud Functions: F# and Visual Basic.