You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This article is an introduction to developing Azure Functions by using C# script (*.csx*).
14
14
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 |
| 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)|
16
22
17
23
This article assumes that you've already read the [Azure Functions developers guide](functions-reference.md).
18
24
19
25
## How .csx works
20
26
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.
22
28
23
29
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.
24
30
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.
26
32
27
33
## Folder structure
28
34
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:
30
36
31
37
```
32
38
FunctionsProject
@@ -45,7 +51,7 @@ FunctionsProject
45
51
46
52
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).
47
53
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.
49
55
50
56
## Binding to arguments
51
57
@@ -350,14 +356,31 @@ The following assemblies are automatically added by the Azure Functions hosting
350
356
*`System.Web.Http`
351
357
*`System.Net.Http.Formatting`
352
358
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)
354
369
355
370
*`Newtonsoft.Json`
356
371
*`Microsoft.WindowsAzure.Storage`
357
372
*`Microsoft.ServiceBus`
358
373
*`Microsoft.AspNet.WebHooks.Receivers`
359
374
*`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
+
```
361
384
362
385
## Referencing custom assemblies
363
386
@@ -383,7 +406,7 @@ By default, the [supported set of Functions extension NuGet packages](functions-
383
406
384
407
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).
385
408
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*:
387
410
388
411
```xml
389
412
<ProjectSdk="Microsoft.NET.Sdk">
@@ -398,7 +421,7 @@ By default, Core Tools reads the function.json files and adds the required packa
398
421
399
422
# [v1.x](#tab/functionsv1)
400
423
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:
402
425
403
426
```json
404
427
{
@@ -418,7 +441,7 @@ Extension bundles aren't supported by version 1.x.
418
441
419
442
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).
420
443
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).
defines the [Storage blob](functions-bindings-storage-blob.md) input or output binding, and
489
512
[TextWriter](/dotnet/api/system.io.textwriter) is a supported output binding type.
490
513
491
-
### Multiple attribute example
514
+
### Multiple attributes example
492
515
493
516
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
0 commit comments