Skip to content

Commit 161de79

Browse files
Merge pull request #211498 from ggailey777/marie
[Functions] Updates to C# script reference
2 parents b9a9be5 + 4d6d26f commit 161de79

File tree

1 file changed

+37
-14
lines changed

1 file changed

+37
-14
lines changed

articles/azure-functions/functions-reference-csharp.md

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Azure Functions C# script developer reference
33
description: Understand how to develop Azure Functions using C# script.
44
ms.topic: conceptual
55
ms.custom: devx-track-csharp
6-
ms.date: 12/12/2017
6+
ms.date: 09/15/2022
77

88
---
99
# Azure Functions C# script (.csx) developer reference
@@ -12,21 +12,27 @@ ms.date: 12/12/2017
1212

1313
This article is an introduction to developing Azure Functions by using C# script (*.csx*).
1414

15-
Azure Functions supports C# and C# script programming languages. If you're looking for guidance on [using C# in a Visual Studio class library project](functions-develop-vs.md), see [C# developer reference](functions-dotnet-class-library.md).
15+
Azure Functions lets you develop functions using C# in one of the following ways:
16+
17+
| Type | Execution process | Code extension | Development environment | Reference |
18+
| --- | ---- | --- | --- | --- |
19+
| C# script | in-process | .csx | [Portal](functions-create-function-app-portal.md)<br/>[Core Tools](functions-run-local.md) | This article |
20+
| C# class library | in-process | .cs | [Visual Studio](functions-develop-vs.md)<br/>[Visual Studio Code](functions-develop-vs-code.md)<br />[Core Tools](functions-run-local.md)s | [In-process C# class library functions](functions-dotnet-class-library.md) |
21+
| C# class library (isolated process)| out-of-process | .cs | [Visual Studio](functions-develop-vs.md)<br/>[Visual Studio Code](functions-develop-vs-code.md)<br />[Core Tools](functions-run-local.md) | [.NET isolated process functions](dotnet-isolated-process-guide.md) |
1622

1723
This article assumes that you've already read the [Azure Functions developers guide](functions-reference.md).
1824

1925
## How .csx works
2026

21-
The C# script experience for Azure Functions is based on the [Azure WebJobs SDK](https://github.com/Azure/azure-webjobs-sdk/wiki/Introduction). Data flows into your C# function via method arguments. Argument names are specified in a `function.json` file, and there are predefined names for accessing things like the function logger and cancellation tokens.
27+
Data flows into your C# function via method arguments. Argument names are specified in a `function.json` file, and there are predefined names for accessing things like the function logger and cancellation tokens.
2228

2329
The *.csx* format allows you to write less "boilerplate" and focus on writing just a C# function. Instead of wrapping everything in a namespace and class, just define a `Run` method. Include any assembly references and namespaces at the beginning of the file as usual.
2430

25-
A function app's *.csx* files are compiled when an instance is initialized. This compilation step means things like cold start may take longer for C# script functions compared to C# class libraries. This compilation step is also why C# script functions are editable in the Azure portal, while C# class libraries are not.
31+
A function app's *.csx* files are compiled when an instance is initialized. This compilation step means things like cold start may take longer for C# script functions compared to C# class libraries. This compilation step is also why C# script functions are editable in the Azure portal, while C# class libraries aren't.
2632

2733
## Folder structure
2834

29-
The folder structure for a C# script project looks like the following:
35+
The folder structure for a C# script project looks like the following example:
3036

3137
```
3238
FunctionsProject
@@ -45,7 +51,7 @@ FunctionsProject
4551

4652
There's a shared [host.json](functions-host-json.md) file that can be used to configure the function app. Each function has its own code file (.csx) and binding configuration file (function.json).
4753

48-
The binding extensions required in [version 2.x and later versions](functions-versions.md) of the Functions runtime are defined in the `extensions.csproj` file, with the actual library files in the `bin` folder. When developing locally, you must [register binding extensions](./functions-bindings-register.md#extension-bundles). When developing functions in the Azure portal, this registration is done for you.
54+
The binding extensions required in [version 2.x and later versions](functions-versions.md) of the Functions runtime are defined in the `extensions.csproj` file, with the actual library files in the `bin` folder. When developing locally, you must [register binding extensions](./functions-bindings-register.md#extension-bundles). When you develop functions in the Azure portal, this registration is done for you.
4955

5056
## Binding to arguments
5157

@@ -350,14 +356,31 @@ The following assemblies are automatically added by the Azure Functions hosting
350356
* `System.Web.Http`
351357
* `System.Net.Http.Formatting`
352358

353-
The following assemblies may be referenced by simple-name (for example, `#r "AssemblyName"`):
359+
The following assemblies may be referenced by simple-name, by runtime version:
360+
361+
# [v2.x+](#tab/functionsv2)
362+
363+
* `Newtonsoft.Json`
364+
* `Microsoft.WindowsAzure.Storage`<sup>*</sup>
365+
366+
<sup>*</sup>Removed in version 4.x of the runtime.
367+
368+
# [v1.x](#tab/functionsv1)
354369

355370
* `Newtonsoft.Json`
356371
* `Microsoft.WindowsAzure.Storage`
357372
* `Microsoft.ServiceBus`
358373
* `Microsoft.AspNet.WebHooks.Receivers`
359374
* `Microsoft.AspNet.WebHooks.Common`
360-
* `Microsoft.Azure.NotificationHubs`
375+
376+
---
377+
378+
379+
In code, assemblies are referenced like the following example:
380+
381+
```csharp
382+
#r "AssemblyName"
383+
```
361384

362385
## Referencing custom assemblies
363386

@@ -383,7 +406,7 @@ By default, the [supported set of Functions extension NuGet packages](functions-
383406

384407
If for some reason you can't use extension bundles in your project, you can also use the Azure Functions Core Tools to install extensions based on bindings defined in the function.json files in your app. When using Core Tools to register extensions, make sure to use the `--csx` option. To learn more, see [Install extensions](functions-run-local.md#install-extensions).
385408

386-
By default, Core Tools reads the function.json files and adds the required packages to an *extensions.csproj* C# class library project file in the root of the function app's file system (wwwroot). Because Core Tools uses dotnet.exe, you can use it to add any NuGet package reference to this extensions file. During installation, Core Tools builds the extensions.csproj to install the required libraries. Here is an example *extensions.csproj* file that adds a reference to *Microsoft.ProjectOxford.Face* version *1.1.0*:
409+
By default, Core Tools reads the function.json files and adds the required packages to an *extensions.csproj* C# class library project file in the root of the function app's file system (wwwroot). Because Core Tools uses dotnet.exe, you can use it to add any NuGet package reference to this extensions file. During installation, Core Tools builds the extensions.csproj to install the required libraries. Here's an example *extensions.csproj* file that adds a reference to *Microsoft.ProjectOxford.Face* version *1.1.0*:
387410

388411
```xml
389412
<Project Sdk="Microsoft.NET.Sdk">
@@ -398,7 +421,7 @@ By default, Core Tools reads the function.json files and adds the required packa
398421

399422
# [v1.x](#tab/functionsv1)
400423

401-
Version 1.x of the Functions runtime uses a *project.json* file to define dependencies. Here is an example *project.json* file:
424+
Version 1.x of the Functions runtime uses a *project.json* file to define dependencies. Here's an example *project.json* file:
402425

403426
```json
404427
{
@@ -418,7 +441,7 @@ Extension bundles aren't supported by version 1.x.
418441

419442
To use a custom NuGet feed, specify the feed in a *Nuget.Config* file in the function app root folder. For more information, see [Configuring NuGet behavior](/nuget/consume-packages/configuring-nuget-behavior).
420443

421-
If you are working on your project only in the portal, you'll need to manually create the extensions.csproj file or a Nuget.Config file directly in the site. To learn more, see [Manually install extensions](functions-how-to-use-azure-function-app-settings.md#manually-install-extensions).
444+
If you're working on your project only in the portal, you'll need to manually create the extensions.csproj file or a Nuget.Config file directly in the site. To learn more, see [Manually install extensions](functions-how-to-use-azure-function-app-settings.md#manually-install-extensions).
422445

423446
## Environment variables
424447

@@ -460,7 +483,7 @@ using (var output = await binder.BindAsync<T>(new BindingTypeAttribute(...)))
460483
```
461484

462485
`BindingTypeAttribute` is the .NET attribute that defines your binding and `T` is an input or output type that's
463-
supported by that binding type. `T` cannot be an `out` parameter type (such as `out JObject`). For example, the
486+
supported by that binding type. `T` can't be an `out` parameter type (such as `out JObject`). For example, the
464487
Mobile Apps table output binding supports
465488
[six output types](https://github.com/Azure/azure-webjobs-sdk-extensions/blob/master/src/WebJobs.Extensions.MobileApps/MobileTableAttribute.cs#L17-L22),
466489
but you can only use [ICollector\<T>](https://github.com/Azure/azure-webjobs-sdk/blob/master/src/Microsoft.Azure.WebJobs/ICollector.cs)
@@ -488,7 +511,7 @@ public static async Task Run(string input, Binder binder)
488511
defines the [Storage blob](functions-bindings-storage-blob.md) input or output binding, and
489512
[TextWriter](/dotnet/api/system.io.textwriter) is a supported output binding type.
490513

491-
### Multiple attribute example
514+
### Multiple attributes example
492515

493516
The preceding example gets the app setting for the function app's main Storage account connection string (which is `AzureWebJobsStorage`). You can specify a custom app setting to use for the Storage account by adding the
494517
[StorageAccountAttribute](https://github.com/Azure/azure-webjobs-sdk/blob/master/src/Microsoft.Azure.WebJobs/StorageAccountAttribute.cs)
@@ -513,7 +536,7 @@ public static async Task Run(string input, Binder binder)
513536
}
514537
```
515538

516-
The following table lists the .NET attributes for each binding type and the packages in which they are defined.
539+
The following table lists the .NET attributes for each binding type and the packages in which they're defined.
517540

518541
> [!div class="mx-codeBreakAll"]
519542
> | Binding | Attribute | Add reference |

0 commit comments

Comments
 (0)