Your Cloud Run function runs in an environment consisting of an operating system version with add-on packages, language support, and the .NET Functions Framework library that supports and invokes your function. This environment is identified by the language version, and is known as the runtime ID.
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 Set up a .NET development environment.
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.
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 Supported language runtimes and base images
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). You can select the preferred runtime for your
function during deployment.
gcloud
To use Cloud Run functions to deploy an HTTP function using the gcloud CLI, see Deploy using the Google Cloud CLI.
Console
If you're using the Google Cloud console, select the runtime when you create and deploy your function. See the Google Cloud console quickstart for detailed instructions.
Source code structure
For Cloud Run functions to find your function's definition, your source code must follow a specific structure. See Write Cloud Run functions for more information.
Specifying dependencies
.NET Cloud Run functions uses
Microsoft Build Engine (MSBuild) project files
which are central to the build and deployment process. You can specify
dependencies for your function in a project file. For C# the file extension is
.csproj
, for F# it is .fsproj
, and for Visual Basic it is .vbproj
.
For more discussion of dependencies and other types of customization, see Customization through Functions Startup classes.