Skip to content

Commit 239ae51

Browse files
Merge pull request #280134 from mattchenderson/net9-prev6
Preview support for .NET 9 in Functions
2 parents df565a0 + 034fba8 commit 239ae51

8 files changed

+74
-14
lines changed

articles/azure-functions/dotnet-isolated-process-guide.md

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Guide for running C# Azure Functions in an isolated worker process
33
description: Learn how to use the .NET isolated worker model to run your C# functions in Azure, which lets you run your functions on currently supported versions of .NET and .NET Framework.
44
ms.service: azure-functions
55
ms.topic: conceptual
6-
ms.date: 12/13/2023
6+
ms.date: 09/05/2024
77
ms.custom:
88
- template-concept
99
- devx-track-dotnet
@@ -63,6 +63,12 @@ The following packages are required to run your .NET functions in an isolated wo
6363
+ [Microsoft.Azure.Functions.Worker]
6464
+ [Microsoft.Azure.Functions.Worker.Sdk]
6565

66+
#### Version 2.x (Preview)
67+
68+
The 2.x versions of the core packages change the supported framework assets and bring in support for new .NET APIs from these later versions. When using .NET 9 (Preview) or later, your app needs to reference version 2.0.0-preview1 or later of both packages.
69+
70+
The 2.0.0-preview1 versions are compatible with code written against version 1.x. However, during the preview period, newer versions may introduce behavior changes that could influence the code you write.
71+
6672
### Extension packages
6773

6874
Because .NET isolated worker process functions use different binding types, they require a unique set of binding extension packages.
@@ -123,7 +129,7 @@ Dependency injection is simplified when compared to .NET in-process functions, w
123129
For a .NET isolated process app, you use the .NET standard way of call [ConfigureServices] on the host builder and use the extension methods on [IServiceCollection] to inject specific services.
124130

125131
The following example injects a singleton service dependency:
126-
132+
127133
```csharp
128134
.ConfigureServices(services =>
129135
{
@@ -138,7 +144,9 @@ This code requires `using Microsoft.Extensions.DependencyInjection;`. To learn m
138144
Dependency injection can be used to interact with other Azure services. You can inject clients from the [Azure SDK for .NET](/dotnet/azure/sdk/azure-sdk-for-dotnet) using the [Microsoft.Extensions.Azure](https://www.nuget.org/packages/Microsoft.Extensions.Azure) package. After installing the package, [register the clients](/dotnet/azure/sdk/dependency-injection#register-clients) by calling `AddAzureClients()` on the service collection in `Program.cs`. The following example configures a [named client](/dotnet/azure/sdk/dependency-injection#configure-multiple-service-clients-with-different-names) for Azure Blobs:
139145

140146
```csharp
147+
using Microsoft.Azure.Functions.Worker;
141148
using Microsoft.Extensions.Azure;
149+
using Microsoft.Extensions.DependencyInjection;
142150
using Microsoft.Extensions.Hosting;
143151

144152
var host = new HostBuilder()
@@ -194,7 +202,7 @@ The [`ILogger<T>`][ILogger&lt;T&gt;] in this example was also obtained through d
194202
195203
### Middleware
196204

197-
.NET isolated also supports middleware registration, again by using a model similar to what exists in ASP.NET. This model gives you the ability to inject logic into the invocation pipeline, and before and after functions execute.
205+
The isolated worker model also supports middleware registration, again by using a model similar to what exists in ASP.NET. This model gives you the ability to inject logic into the invocation pipeline, and before and after functions execute.
198206

199207
The [ConfigureFunctionsWorkerDefaults] extension method has an overload that lets you register your own middleware, as you can see in the following example.
200208

@@ -225,6 +233,10 @@ The isolated worker model uses `System.Text.Json` by default. You can customize
225233
The following example shows this using `ConfigureFunctionsWebApplication`, but it will also work for `ConfigureFunctionsWorkerDefaults`:
226234

227235
```csharp
236+
using Microsoft.Azure.Functions.Worker;
237+
using Microsoft.Extensions.DependencyInjection;
238+
using Microsoft.Extensions.Hosting;
239+
228240
var host = new HostBuilder()
229241
.ConfigureFunctionsWebApplication((IFunctionsWorkerApplicationBuilder builder) =>
230242
{
@@ -239,11 +251,17 @@ var host = new HostBuilder()
239251
});
240252
})
241253
.Build();
254+
255+
host.Run();
242256
```
243257

244258
You might wish to instead use JSON.NET (`Newtonsoft.Json`) for serialization. To do this, you would install the [`Microsoft.Azure.Core.NewtonsoftJson`](https://www.nuget.org/packages/Microsoft.Azure.Core.NewtonsoftJson) package. Then, in your service registration, you would reassign the `Serializer` property on the `WorkerOptions` configuration. The following example shows this using `ConfigureFunctionsWebApplication`, but it will also work for `ConfigureFunctionsWorkerDefaults`:
245259

246260
```csharp
261+
using Microsoft.Azure.Functions.Worker;
262+
using Microsoft.Extensions.DependencyInjection;
263+
using Microsoft.Extensions.Hosting;
264+
247265
var host = new HostBuilder()
248266
.ConfigureFunctionsWebApplication((IFunctionsWorkerApplicationBuilder builder) =>
249267
{
@@ -257,6 +275,8 @@ var host = new HostBuilder()
257275
});
258276
})
259277
.Build();
278+
279+
host.Run();
260280
```
261281

262282
## Methods recognized as functions
@@ -440,6 +460,10 @@ To enable ASP.NET Core integration for HTTP:
440460
ASP.NET Core has its own serialization layer, and it is not affected by [customizing general serialization configuration](#customizing-json-serialization). To customize the serialization behavior used for your HTTP triggers, you need to include an `.AddMvc()` call as part of service registration. The returned `IMvcBuilder` can be used to modify ASP.NET Core's JSON serialization settings. The following example shows how to configure JSON.NET (`Newtonsoft.Json`) for serialization using this approach:
441461

442462
```csharp
463+
using Microsoft.Azure.Functions.Worker;
464+
using Microsoft.Extensions.DependencyInjection;
465+
using Microsoft.Extensions.Hosting;
466+
443467
var host = new HostBuilder()
444468
.ConfigureFunctionsWebApplication()
445469
.ConfigureServices(services =>
@@ -486,7 +510,7 @@ public class MyFunction {
486510

487511
The logger can also be obtained from a [FunctionContext] object passed to your function. Call the [GetLogger&lt;T&gt;] or [GetLogger] method, passing a string value that is the name for the category in which the logs are written. The category is usually the name of the specific function from which the logs are written. To learn more about categories, see the [monitoring article](functions-monitoring.md#log-levels-and-categories).
488512

489-
Use the methods of [`ILogger<T>`][ILogger&lt;T&gt;] and [`ILogger`][ILogger] to write various log levels, such as `LogWarning` or `LogError`. To learn more about log levels, see the [monitoring article](functions-monitoring.md#log-levels-and-categories). You can customize the log levels for components added to your code by registering filters as part of the `HostBuilder` configuration:
513+
Use the methods of [`ILogger<T>`][ILogger&lt;T&gt;] and [`ILogger`][ILogger] to write various log levels, such as `LogWarning` or `LogError`. To learn more about log levels, see the [monitoring article](functions-monitoring.md#log-levels-and-categories). You can customize the log levels for components added to your code by registering filters:
490514

491515
```csharp
492516
using Microsoft.Azure.Functions.Worker;
@@ -514,12 +538,17 @@ var host = new HostBuilder()
514538
As part of configuring your app in `Program.cs`, you can also define the behavior for how errors are surfaced to your logs. By default, exceptions thrown by your code can end up wrapped in an `RpcException`. To remove this extra layer, set the `EnableUserCodeException` property to "true" as part of configuring the builder:
515539

516540
```csharp
541+
using Microsoft.Azure.Functions.Worker;
542+
using Microsoft.Extensions.Hosting;
543+
517544
var host = new HostBuilder()
518545
.ConfigureFunctionsWorkerDefaults(builder => {}, options =>
519546
{
520547
options.EnableUserCodeException = true;
521548
})
522549
.Build();
550+
551+
host.Run();
523552
```
524553

525554
### Application Insights
@@ -570,6 +599,11 @@ The call to `ConfigureFunctionsApplicationInsights()` adds an `ITelemetryModule`
570599
The rest of your application continues to work with `ILogger` and `ILogger<T>`. However, by default, the Application Insights SDK adds a logging filter that instructs the logger to capture only warnings and more severe logs. If you want to disable this behavior, remove the filter rule as part of service configuration:
571600

572601
```csharp
602+
using Microsoft.Azure.Functions.Worker;
603+
using Microsoft.Extensions.DependencyInjection;
604+
using Microsoft.Extensions.Hosting;
605+
using Microsoft.Extensions.Logging;
606+
573607
var host = new HostBuilder()
574608
.ConfigureFunctionsWorkerDefaults()
575609
.ConfigureServices(services => {
@@ -633,7 +667,7 @@ Placeholders are a platform capability that improves cold start for apps targeti
633667
az functionapp config set -g <groupName> -n <appName> --net-framework-version <framework>
634668
```
635669
636-
In this example, also replace `<framework>` with the appropriate version string, such as `v8.0`, `v7.0`, or `v6.0`, according to your target .NET version.
670+
In this example, also replace `<framework>` with the appropriate version string, such as `v8.0`, according to your target .NET version.
637671
638672
1. Make sure that your function app is configured to use a 64-bit process, which you can do by using this [az functionapp config set](/cli/azure/functionapp/config#az-functionapp-config-set) command:
639673
@@ -822,7 +856,15 @@ Before a generally available release, a .NET version might be released in a _Pre
822856

823857
While it might be possible to target a given release from a local Functions project, function apps hosted in Azure might not have that release available. Azure Functions can only be used with Preview or Go-live releases noted in this section.
824858

825-
Azure Functions doesn't currently work with any "Preview" or "Go-live" .NET releases. See [Supported versions][supported-versions] for a list of generally available releases that you can use.
859+
Azure Functions currently can be used with the following "Preview" or "Go-live" .NET releases:
860+
861+
| Operating system | .NET preview version |
862+
| - | - |
863+
| Linux | .NET 9 Preview 7<sup>1</sup> |
864+
865+
<sup>1</sup> To successfully target .NET 9, your project needs to reference the [2.x versions of the core packages](#version-2x-preview). If using Visual Studio, .NET 9 requires version 17.12 or later.
866+
867+
See [Supported versions][supported-versions] for a list of generally available releases that you can use.
826868

827869
### Using a preview .NET SDK
828870

@@ -831,12 +873,26 @@ To use Azure Functions with a preview version of .NET, you need to update your p
831873
1. Installing the relevant .NET SDK version in your development
832874
1. Changing the `TargetFramework` setting in your `.csproj` file
833875

834-
When deploying to a function app in Azure, you also need to ensure that the framework is made available to the app. To do so on Windows, you can use the following CLI command. Replace `<groupName>` with the name of the resource group, and replace `<appName>` with the name of your function app. Replace `<framework>` with the appropriate version string, such as `v8.0`.
876+
When you deploy to your function app in Azure, you also need to ensure that the framework is made available to the app. During the preview period, some tools and experiences may not surface the new preview version as an option. If you do not see the preview version included in the Azure Portal, for example, you can use the REST API, Bicep templates, or the Azure CLI to configure the version manually.
877+
878+
### [Windows](#tab/windows)
879+
880+
For apps hosted on Windows, use the following Azure CLI command. Replace `<groupName>` with the name of the resource group, and replace `<appName>` with the name of your function app. Replace `<framework>` with the appropriate version string, such as `v8.0`.
835881

836882
```azurecli
837883
az functionapp config set -g <groupName> -n <appName> --net-framework-version <framework>
838884
```
839885

886+
### [Linux](#tab/linux)
887+
888+
For apps hosted on Linux, use the following Azure CLI command. Replace `<groupName>` with the name of the resource group, and replace `<appName>` with the name of your function app. Replace `<version>` with the appropriate version string, such as `8.0`.
889+
890+
```azurecli
891+
az functionapp config set -g <groupName> -n <appName> --linux-fx-version "dotnet-isolated|<version>"
892+
```
893+
894+
---
895+
840896
### Considerations for using .NET preview versions
841897

842898
Keep these considerations in mind when using Functions with preview versions of .NET:

articles/azure-functions/functions-core-tools-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ When you supply `<PROJECT_FOLDER>`, the project is created in a new folder with
4949
| **`--model`** | Sets the desired programming model for a target language when more than one model is available. Supported options are `V1` and `V2` for Python and `V3` and `V4` for Node.js. For more information, see the [Python developer guide](functions-reference-python.md#programming-model) and the [Node.js developer guide](functions-reference-node.md), respectively. |
5050
| **`--source-control`** | Controls whether a git repository is created. By default, a repository isn't created. When `true`, a repository is created. |
5151
| **`--worker-runtime`** | Sets the language runtime for the project. Supported values are: `csharp`, `dotnet`, `dotnet-isolated`, `javascript`,`node` (JavaScript), `powershell`, `python`, and `typescript`. For Java, use [Maven](functions-reference-java.md#create-java-functions). To generate a language-agnostic project with just the project files, use `custom`. When not set, you're prompted to choose your runtime during initialization. |
52-
| **`--target-framework`** | Sets the target framework for the function app project. Valid only with `--worker-runtime dotnet-isolated`. Supported values are: `net6.0` (default), `net7.0`, `net8.0`, and `net48` (.NET Framework 4.8). |
52+
| **`--target-framework`** | Sets the target framework for the function app project. Valid only with `--worker-runtime dotnet-isolated`. Supported values are: `net9.0` (preview), `net8.0` (default), `net6.0`, and `net48` (.NET Framework 4.8). |
5353
|
5454

5555
> [!NOTE]

articles/azure-functions/functions-versions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ zone_pivot_groups: programming-languages-set-functions
1414
| Version | Support level | Description |
1515
| --- | --- | --- |
1616
| 4.x | GA | **_Recommended runtime version for functions in all languages._** Check out [Supported language versions](#languages). |
17-
| 1.x | GA ([support ends September 14, 2026](https://aka.ms/azure-functions-retirements/hostv1)) | Supported only for C# apps that must use .NET Framework. This version is in maintenance mode, with enhancements provided only in later versions. **Support will end for version 1.x on September 14, 2026.** We highly recommend you [migrate your apps to version 4.x](migrate-version-1-version-4.md?pivots=programming-language-csharp), which supports .NET Framework 4.8, .NET 6, and .NET 8.|
17+
| 1.x | GA ([support ends September 14, 2026](https://aka.ms/azure-functions-retirements/hostv1)) | Supported only for C# apps that must use .NET Framework. This version is in maintenance mode, with enhancements provided only in later versions. **Support will end for version 1.x on September 14, 2026.** We highly recommend you [migrate your apps to version 4.x](migrate-version-1-version-4.md?pivots=programming-language-csharp), which supports .NET Framework 4.8, .NET 6, .NET 8, and .NET 9.|
1818

1919
> [!IMPORTANT]
2020
> As of December 13, 2022, function apps running on versions 2.x and 3.x of the Azure Functions runtime have reached the end of extended support. For more information, see [Retired versions](#retired-versions).
@@ -131,7 +131,7 @@ In Visual Studio, you select the runtime version when you create a project. Azur
131131
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
132132
```
133133

134-
You can choose `net8.0`, `net6.0`, or `net48` as the target framework if you are using the [isolated worker model](dotnet-isolated-process-guide.md). If you are using the [in-process model](./functions-dotnet-class-library.md), you can choose `net8.0` or `net6.0`, and you must include the `Microsoft.NET.Sdk.Functions` extension set to at least `4.4.0`.
134+
If you are using the [isolated worker model](dotnet-isolated-process-guide.md), you can choose, `net8.0`, `net6.0`, or `net48` as the target framework. You can also choose to use [preview support](./dotnet-isolated-process-guide.md#preview-net-versions) for `net9.0`. If you are using the [in-process model](./functions-dotnet-class-library.md), you can choose `net8.0` or `net6.0`, and you must include the `Microsoft.NET.Sdk.Functions` extension set to at least `4.4.0`.
135135

136136
.NET 7 was previously supported on the isolated worker model but reached the end of official support on [May 14, 2024][dotnet-policy].
137137

articles/azure-functions/migrate-dotnet-to-isolated-model.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ On version 4.x of the Functions runtime, your .NET function app targets .NET 6 w
5454
> [!TIP]
5555
> **We recommend upgrading to .NET 8 on the isolated worker model.** This provides a quick migration path to the fully released version with the longest support window from .NET.
5656
57-
This guide doesn't present specific examples for .NET 7 or .NET 6. If you need to target these versions, you can adapt the .NET 8 examples.
57+
This guide doesn't present specific examples for .NET 9 (Preview) or .NET 6. If you need to target these versions, you can adapt the .NET 8 examples.
5858

5959
## Prepare for migration
6060

articles/azure-functions/update-language-versions.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ Use these steps to update the project on your local computer:
3737

3838
1. Ensure you have [installed the target version of the .NET SDK](https://dotnet.microsoft.com/download/dotnet).
3939

40-
1. Update your references to the latest stable versions of: [Microsoft.Azure.Functions.Worker](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker/) and [Microsoft.Azure.Functions.Worker.Sdk](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Sdk/).
40+
If you are targeting a preview version, consult the [Functions guidance for preview .NET versions](./dotnet-isolated-process-guide.md#preview-net-versions) to ensure that the version is supported. Additional steps may be required for .NET previews.
41+
42+
1. Update your references to the latest versions of: [Microsoft.Azure.Functions.Worker](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker/) and [Microsoft.Azure.Functions.Worker.Sdk](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Sdk/).
4143

4244
1. Update your project's target framework to the new version. For C# projects, you must update the `<TargetFramework>` element in the `.csproj` file. See [Target frameworks](/dotnet/standard/frameworks) for specifics related to the chosen version.
4345

includes/functions-dotnet-migrate-v4-versions.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ When you migrate your function app, you have the opportunity to choose the targe
1212

1313
| .NET version | [.NET Official Support Policy] release type | Functions process model<sup>1,2</sup> |
1414
| --- | --- | --- |
15+
| .NET 9 | Preview<sup>3</sup> | [Isolated worker model] |
1516
| .NET 8 | LTS (end of support November 10, 2026) | [Isolated worker model],<br/>[In-process model]<sup>2</sup> |
1617
| .NET 6 | LTS (end of support November 12, 2024) | [Isolated worker model],<br/>[In-process model]<sup>2</sup> |
1718
| .NET Framework 4.8 | [See policy][netfxpolicy] | [Isolated worker model] |
@@ -20,7 +21,7 @@ When you migrate your function app, you have the opportunity to choose the targe
2021

2122
<sup>2</sup> Support ends for the in-process model on November 10, 2026. For more information, see [this support announcement](https://aka.ms/azure-functions-retirements/in-process-model). For continued full support, you should [migrate your apps to the isolated worker model](../articles/azure-functions/migrate-dotnet-to-isolated-model.md).
2223

23-
<!-- <sup>2</sup> See [Preview .NET versions in the isolated worker model](../articles/azure-functions/dotnet-isolated-process-guide.md#preview-net-versions) for details on support, current restrictions, and instructions for using the preview version. -->
24+
<sup>3</sup> See [Preview .NET versions in the isolated worker model](../articles/azure-functions/dotnet-isolated-process-guide.md#preview-net-versions) for details on support, current restrictions, and instructions for using the preview version.
2425

2526
[.NET Official Support Policy]: https://dotnet.microsoft.com/platform/support/policy
2627
[netfxpolicy]: https://dotnet.microsoft.com/platform/support/policy/dotnet-framework

0 commit comments

Comments
 (0)