[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-05 (世界標準時間)。"],[[["\u003cp\u003eCloud Run functions operate within a specific runtime environment, which includes the operating system, add-on packages, language support, and the Functions Framework library.\u003c/p\u003e\n"],["\u003cp\u003eThe .NET template package can be installed via the command \u003ccode\u003edotnet new install Google.Cloud.Functions.Templates\u003c/code\u003e, and supports C#, F#, and Visual Basic for function development.\u003c/p\u003e\n"],["\u003cp\u003eDifferent versions of the .NET Functions Framework are available, with Version 1 supporting .NET Core 3.1 and later, and Version 2 supporting .NET 6 and later, and projects using version 1 can be updated to version 2.\u003c/p\u003e\n"],["\u003cp\u003eWhen deploying a Cloud Run function, you must specify a .NET runtime that matches the target framework set in your project file, using the \u003ccode\u003e--runtime\u003c/code\u003e parameter in the Google Cloud CLI or through the console.\u003c/p\u003e\n"],["\u003cp\u003eDependencies for your .NET Cloud Run function can be specified directly in the project file.\u003c/p\u003e\n"]]],[],null,["# The .NET Runtime\n================\n\nOverview\n--------\n\nYour Cloud Run function runs in an environment consisting of an operating\nsystem version plus add-on packages, language support, and\nthe Functions Framework library that supports and invokes your function.\nThis environment is identified by the language version, and is known as the\nruntime.\n\nFor information about runtimes in general, and to learn which Ubuntu version\neach .NET runtime uses, see the [Cloud Run functions execution\nenvironment](/functions/1stgendocs/concepts/execution-environment#.net-core).\n\nTemplate package\n----------------\n\nThe template package helps you to create new functions. To use it:\n\n1. Install the [.NET SDK](https://dotnet.microsoft.com/download).\n\n2. Install the template package:\n\n dotnet new install Google.Cloud.Functions.Templates\n\n| **Note:** versions of the .NET SDK earlier than .NET 7 use `dotnet new -i` instead of `dotnet new install`.\n\nTemplates are provided for the three kinds of functions in C# (the default), F#,\nand Visual Basic. When creating a new project from a template, specify\n`-lang f#` to create an F# project, or `-lang vb` to create a Visual Basic\nproject. For more information, see:\n\n- [.NET Languages](/functions/1stgendocs/concepts/dotnet-langs) (for F# and Visual Basic)\n\nSelect a .NET Functions Framework version\n-----------------------------------------\n\nDifferent versions of the .NET Functions Framework support different runtimes.\nVersion 1 supports .NET Core 3.1 and later, with templates defaulting to\n.NET Core 3.1. Version 2 supports .NET 6 and later, with templates defaulting\nto .NET 6.\n\nTo upgrade an existing project using .NET Functions Framework version 1,\nedit the project file (or use Visual Studio) to update all dependencies that\nbegin with `Google.Cloud.Functions` to the latest version, and set the\ntarget framework to .NET 6.\n\nSelect your runtime\n-------------------\n\nCloud Run functions supports several versions of .NET, listed on the\n[Runtime support](/functions/1stgendocs/runtime-support#.net-core) page. When you deploy\nyour function, you must specify\na .NET runtime corresponding to the target framework in your project file\n(`MyFunction.csproj` or similar). To specify your .NET runtime: \n\n### gcloud\n\nIf you're using the Google Cloud CLI, specify the runtime\nby using the `--runtime` parameter. The `--entry-point` flag specifies the\nfully qualified class name (FQN). For example: \n\n```bash\ngcloud functions deploy NAME --no-gen2 --entry-point FQN --no-gen2 --runtime dotnet6 --trigger-http\n```\n\nFor more deployment parameters, see\n[Deploy a Cloud Run function](/functions/1stgendocs/deploy#basics).\n\n### Console\n\nIf you're using the Google Cloud console, see the [Google Cloud console\nquickstart](/functions/1stgendocs/console-quickstart-1st-gen) for\ndetailed instructions.\n\nFunction preparation\n--------------------\n\nYou can prepare a function directly from the Google Cloud console or write it on\nyour local machine and upload it. To prepare your local machine for .NET\ndevelopment, see [Setting up a .NET development\nenvironment](/dotnet/docs/setup).\n\nThe library that invokes your function is the\n[.NET Functions Framework](/functions/1stgendocs/functions-framework).\n| **Note:** The only type of [event-driven functions](/functions/1stgendocs/writing#types_of_cloud_functions) .NET supports are [CloudEvent functions](/functions/1stgendocs/writing#cloudevent_functions).\n\nSource code structure\n---------------------\n\nIn order for Cloud Run functions to find your function's definition, each\nruntime has certain structuring requirements for your source code. See [Write\nCloud Run functions](/functions/1stgendocs/writing#functions-writing-file-structuring-csharp)\nfor more information.\n\nSpecifying dependencies\n-----------------------\n\nYou can specify dependencies for your function by adding them to a project file.\nFor more information, see [Specifying dependencies in\n.NET](/functions/1stgendocs/writing/specifying-dependencies-dotnet).\n\nWhat's next\n-----------\n\n- [Learn about the other .NET languages](/functions/1stgendocs/concepts/dotnet-langs) you can use to write Cloud Run functions: F# and Visual Basic."]]