Skip to content

Commit 488649b

Browse files
authored
Merge pull request #198137 from mattchenderson/netfxworker
adding .NET Framework Isolated content
2 parents bc02cde + b37c183 commit 488649b

File tree

5 files changed

+90
-28
lines changed

5 files changed

+90
-28
lines changed

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

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ description: Learn how to use a .NET isolated process to run your C# functions i
44

55
ms.service: azure-functions
66
ms.topic: conceptual
7-
ms.date: 06/01/2021
7+
ms.date: 05/12/2022
88
ms.custom: template-concept
99
recommendations: false
1010
#Customer intent: As a developer, I need to know how to create functions that run in an isolated process so that I can run my function code on current (not LTS) releases of .NET.
1111
---
1212

1313
# Guide for running C# Azure Functions in an isolated process
1414

15-
This article is an introduction to using C# to develop .NET isolated process functions, which run out-of-process in Azure Functions. Running out-of-process lets you decouple your function code from the Azure Functions runtime. Isolated process C# functions run on both .NET 5.0 and .NET 6.0. [In-process C# class library functions](functions-dotnet-class-library.md) aren't supported on .NET 5.0.
15+
This article is an introduction to using C# to develop .NET isolated process functions, which run out-of-process in Azure Functions. Running out-of-process lets you decouple your function code from the Azure Functions runtime. Isolated process C# functions run on .NET 5.0, .NET 6.0, and .NET Framework 4.8 (preview support). [In-process C# class library functions](functions-dotnet-class-library.md) aren't supported on .NET 5.0.
1616

1717
| Getting started | Concepts| Samples |
1818
|--|--|--|
@@ -26,7 +26,7 @@ Because these functions run in a separate process, there are some [feature and f
2626

2727
### Benefits of running out-of-process
2828

29-
When running out-of-process, your .NET functions can take advantage of the following benefits:
29+
When your .NET functions run out-of-process, you can take advantage of the following benefits:
3030

3131
+ Fewer conflicts: because the functions run in a separate process, assemblies used in your app won't conflict with different version of the same assemblies used by the host process.
3232
+ Full control of the process: you control the start-up of the app and can control the configurations used and the middleware started.
@@ -42,13 +42,16 @@ A .NET isolated function project is basically a .NET console app project that ta
4242
+ [local.settings.json](functions-develop-local.md#local-settings-file) file.
4343
+ C# project file (.csproj) that defines the project and dependencies.
4444
+ Program.cs file that's the entry point for the app.
45+
+ Any code files [defining your functions](#bindings).
4546

47+
For complete examples, see the [.NET 6 isolated sample project](https://github.com/Azure/azure-functions-dotnet-worker/tree/main/samples/FunctionApp) and the [.NET Framework 4.8 isolated sample project](https://github.com/Azure/azure-functions-dotnet-worker/tree/main/samples/NetFxWorker).
48+
4649
> [!NOTE]
4750
> To be able to publish your isolated function project to either a Windows or a Linux function app in Azure, you must set a value of `dotnet-isolated` in the remote [FUNCTIONS_WORKER_RUNTIME](functions-app-settings.md#functions_worker_runtime) application setting. To support [zip deployment](deployment-zip-push.md) and [running from the deployment package](run-functions-from-deployment-package.md) on Linux, you also need to update the `linuxFxVersion` site config setting to `DOTNET-ISOLATED|6.0`. To learn more, see [Manual version updates on Linux](set-runtime-version.md#manual-version-updates-on-linux).
4851
4952
## Package references
5053

51-
When running out-of-process, your .NET project uses a unique set of packages, which implement both core functionality and binding extensions.
54+
When your functions run out-of-process, your .NET project uses a unique set of packages, which implement both core functionality and binding extensions.
5255

5356
### Core packages
5457

@@ -65,7 +68,7 @@ You'll find these extension packages under [Microsoft.Azure.Functions.Worker.Ext
6568

6669
## Start-up and configuration
6770

68-
When using .NET isolated functions, you have access to the start-up of your function app, which is usually in Program.cs. You're responsible for creating and starting your own host instance. As such, you also have direct access to the configuration pipeline for your app. When running out-of-process, you can much more easily add configurations, inject dependencies, and run your own middleware.
71+
When using .NET isolated functions, you have access to the start-up of your function app, which is usually in Program.cs. You're responsible for creating and starting your own host instance. As such, you also have direct access to the configuration pipeline for your app. When you run your functions out-of-process, you can much more easily add configurations, inject dependencies, and run your own middleware.
6972

7073
The following code shows an example of a [HostBuilder] pipeline:
7174

@@ -77,6 +80,9 @@ A [HostBuilder] is used to build and return a fully initialized [IHost] instance
7780

7881
:::code language="csharp" source="~/azure-functions-dotnet-worker/samples/FunctionApp/Program.cs" id="docsnippet_host_run":::
7982

83+
> [!IMPORTANT]
84+
> If your project targets .NET Framework 4.8, you also need to add `FunctionsDebugger.Enable();` before creating the HostBuilder. It should be the first line of your `Main()` method. See [Debugging when targeting .NET Framework](#debugging-when-targeting-net-framework) for more information.
85+
8086
### Configuration
8187

8288
The [ConfigureFunctionsWorkerDefaults] method is used to add the settings required for the function app to run out-of-process, which includes the following functionality:
@@ -128,7 +134,7 @@ The following is an example of a middleware implementation which reads the `Http
128134

129135
:::code language="csharp" source="~/azure-functions-dotnet-worker/samples/CustomMiddleware/StampHttpHeaderMiddleware.cs" id="docsnippet_middleware_example_stampheader" :::
130136

131-
For a more complete example of using custom middlewares in your function app, see the [custom middleware reference sample](https://github.com/Azure/azure-functions-dotnet-worker/blob/main/samples/CustomMiddleware).
137+
For a more complete example of using custom middleware in your function app, see the [custom middleware reference sample](https://github.com/Azure/azure-functions-dotnet-worker/blob/main/samples/CustomMiddleware).
132138

133139
## Execution context
134140

@@ -190,13 +196,62 @@ Use various methods of [ILogger] to write various log levels, such as `LogWarnin
190196

191197
An [ILogger] is also provided when using [dependency injection](#dependency-injection).
192198

199+
## Debugging when targeting .NET Framework
200+
201+
If your isolated project targets .NET Framework 4.8, the current preview scope requires manual steps to enable debugging. These steps are not required if using another target framework.
202+
203+
Your app should start with a call to `FunctionsDebugger.Enable();` as its first operation. This occurs in the `Main()` method before initializing a HostBuilder. Your `Program.cs` file should look similar to the following:
204+
205+
```csharp
206+
using System;
207+
using System.Diagnostics;
208+
using Microsoft.Extensions.Hosting;
209+
using Microsoft.Azure.Functions.Worker;
210+
using NetFxWorker;
211+
212+
namespace MyDotnetFrameworkProject
213+
{
214+
internal class Program
215+
{
216+
static void Main(string[] args)
217+
{
218+
FunctionsDebugger.Enable();
219+
220+
var host = new HostBuilder()
221+
.ConfigureFunctionsWorkerDefaults()
222+
.Build();
223+
224+
host.Run();
225+
}
226+
}
227+
}
228+
```
229+
230+
Next, you need to manually attach to the process using a .NET Framework debugger. Visual Studio doesn't do this automatically for isolated process .NET Framework apps yet, and the "Start Debugging" operation should be avoided.
231+
232+
In your project directory (or its build output directory), run:
233+
234+
```azurecli
235+
func host start --dotnet-isolated-debug
236+
```
237+
238+
This will start your worker, and the process will stop with the following message:
239+
240+
```azurecli
241+
Azure Functions .NET Worker (PID: <process id>) initialized in debug mode. Waiting for debugger to attach...
242+
```
243+
244+
Where `<process id>` is the ID for your worker process. You can now use Visual Studio to manually attach to the process. For instructions on this operation, see [How to attach to a running process](/visualstudio/debugger/attach-to-running-processes-with-the-visual-studio-debugger#BKMK_Attach_to_a_running_process).
245+
246+
Once the debugger is attached, the process execution will resume and you will be able to debug.
247+
193248
## Differences with .NET class library functions
194249

195250
This section describes the current state of the functional and behavioral differences running on out-of-process compared to .NET class library functions running in-process:
196251

197252
| Feature/behavior | In-process | Out-of-process |
198253
| ---- | ---- | ---- |
199-
| .NET versions | .NET Core 3.1<br/>.NET 6.0 | .NET 5.0<br/>.NET 6.0 |
254+
| .NET versions | .NET Core 3.1<br/>.NET 6.0 | .NET 5.0<br/>.NET 6.0<br/>.NET Framework 4.8 (Preview) |
200255
| Core packages | [Microsoft.NET.Sdk.Functions](https://www.nuget.org/packages/Microsoft.NET.Sdk.Functions/) | [Microsoft.Azure.Functions.Worker](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker/)<br/>[Microsoft.Azure.Functions.Worker.Sdk](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Sdk) |
201256
| Binding extension packages | [Microsoft.Azure.WebJobs.Extensions.*](https://www.nuget.org/packages?q=Microsoft.Azure.WebJobs.Extensions) | Under [Microsoft.Azure.Functions.Worker.Extensions.*](https://www.nuget.org/packages?q=Microsoft.Azure.Functions.Worker.Extensions) |
202257
| Logging | [ILogger] passed to the function | [ILogger] obtained from [FunctionContext] |

articles/azure-functions/functions-dotnet-class-library.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
title: Develop C# class library functions using Azure Functions
3-
description: Understand how to use C# to develop and publish code as class libraries that runs in-process with the Azure Functions runtime.
3+
description: Understand how to use C# to develop and publish code as class libraries that run in-process with the Azure Functions runtime.
44

55
ms.topic: conceptual
66
ms.devlang: csharp
77
ms.custom: devx-track-csharp
8-
ms.date: 02/08/2022
8+
ms.date: 05/12/2022
99

1010
---
1111
# Develop C# class library functions using Azure Functions
@@ -15,7 +15,7 @@ ms.date: 02/08/2022
1515
This article is an introduction to developing Azure Functions by using C# in .NET class libraries.
1616

1717
>[!IMPORTANT]
18-
>This article supports .NET class library functions that run in-process with the runtime. Functions also supports .NET 5.x by running your C# functions out-of-process and isolated from the runtime. To learn more, see [.NET isolated process functions](dotnet-isolated-process-guide.md).
18+
>This article supports .NET class library functions that run in-process with the runtime. Your C# functions can also run out-of-process and isolated from the Functions runtime. The isolated model is the only way to run .NET 5.x and the preview of .NET Framework 4.8 using recent versions of the Functions runtime. To learn more, see [.NET isolated process functions](dotnet-isolated-process-guide.md).
1919
2020
As a C# developer, you may also be interested in one of the following articles:
2121

@@ -170,7 +170,7 @@ The generated *function.json* file includes a `configurationSource` property tha
170170

171171
The *function.json* file generation is performed by the NuGet package [Microsoft\.NET\.Sdk\.Functions](https://www.nuget.org/packages/Microsoft.NET.Sdk.Functions).
172172

173-
The same package is used for both version 1.x and 2.x of the Functions runtime. The target framework is what differentiates a 1.x project from a 2.x project. Here are the relevant parts of *.csproj* files, showing different target frameworks with the same `Sdk` package:
173+
The same package is used for both version 1.x and 2.x of the Functions runtime. The target framework is what differentiates a 1.x project from a 2.x project. Here are the relevant parts of the `.csproj` files, showing different target frameworks with the same `Sdk` package:
174174

175175
# [v2.x+](#tab/v2)
176176

0 commit comments

Comments
 (0)