Skip to content

Commit 4138fd7

Browse files
authored
Merge pull request #42043 from ggailey777/current
Adding bindings info to function in VS
2 parents 71117f5 + f63fd6d commit 4138fd7

7 files changed

+88
-153
lines changed

articles/azure-functions/functions-create-your-first-function-visual-studio.experimental.md

Lines changed: 0 additions & 105 deletions
This file was deleted.

articles/azure-functions/functions-create-your-first-function-visual-studio.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ ms.tgt_pltfrm: multiple
1717
ms.workload: na
1818
ms.date: 05/22/2018
1919
ms.author: glenga
20-
ms.custom: mvc, devcenter
21-
experimental: true
22-
experiment_id: 23113853-34f2-4f
20+
ms.custom: mvc, devcenter, 23113853-34f2-4f
2321

2422
---
2523
# Create your first function using Visual Studio
@@ -90,9 +88,8 @@ You must have a function app in your Azure subscription before you can publish y
9088
9189
## Next steps
9290

93-
You have used Visual Studio to create and publish a C# function app with a simple HTTP triggered function.
94-
95-
* To learn how to configure your project to support other types of triggers and bindings, see the [Configure the project for local development](functions-develop-vs.md#configure-the-project-for-local-development) section in [Azure Functions Tools for Visual Studio](functions-develop-vs.md).
96-
* To learn more about local testing and debugging using the Azure Functions Core Tools, see [Code and test Azure Functions locally](functions-run-local.md).
97-
* To learn more about developing functions as .NET class libraries, see [Using .NET class libraries with Azure Functions](functions-dotnet-class-library.md).
91+
You have used Visual Studio to create and publish a C# function app with a simple HTTP triggered function.
9892

93+
* [Learn how to add input and output bindings that integrate with other services.](functions-develop-vs.md#add-bindings)
94+
* [Learn more about local testing and debugging using the Azure Functions Core Tools.](functions-run-local.md#vs-debug)
95+
* [Learn more about developing functions as .NET class libraries](functions-dotnet-class-library.md).

articles/azure-functions/functions-develop-vs.md

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ms.workload: na
1212
ms.tgt_pltfrm: dotnet
1313
ms.devlang: na
1414
ms.topic: article
15-
ms.date: 03/13/2018
15+
ms.date: 05/23/2018
1616
ms.author: glenga
1717
---
1818
# Azure Functions Tools for Visual Studio
@@ -27,7 +27,7 @@ The Azure Functions Tools provides the following benefits:
2727
* Develop and deploy pre-compiled C# functions. Pre-complied functions provide a better cold-start performance than C# script-based functions.
2828
* Code your functions in C# while having all of the benefits of Visual Studio development.
2929

30-
This topic shows you how to use the Azure Functions Tools for Visual Studio 2017 to develop your functions in C#. You also learn how to publish your project to Azure as a .NET assembly.
30+
This article shows you how to use the Azure Functions Tools for Visual Studio 2017 to develop your functions in C#. You also learn how to publish your project to Azure as a .NET assembly.
3131

3232
> [!IMPORTANT]
3333
> Don't mix local development with portal development in the same function app. When you publish from a local project to a function app, the deployment process overwrites any functions that you developed in the portal.
@@ -70,15 +70,15 @@ To create and deploy functions, you also need:
7070

7171
4. After the update is complete, choose **Close** and restart Visual Studio.
7272

73-
## Create an Azure Functions project
73+
## Create an Azure Functions project
7474

7575
[!INCLUDE [Create a project using the Azure Functions](../../includes/functions-vstools-create.md)]
7676

7777
The project template creates a C# project, installs the `Microsoft.NET.Sdk.Functions` NuGet package, and sets the target framework. Functions 1.x targets the .NET Framework, and Functions 2.x targets .NET Standard. The new project has the following files:
7878

7979
* **host.json**: Lets you configure the Functions host. These settings apply both when running locally and in Azure. For more information, see [host.json reference](functions-host-json.md).
80-
81-
* **local.settings.json**: Maintains settings used when running functions locally. These settings are not used by Azure, they are used by the [Azure Functions Core Tools](functions-run-local.md). Use this file to specify settings, such as connection strings to other Azure services. Add a new key to the **Values** array for each connection required by functions in your project. For more information, see [Local settings file](functions-run-local.md#local-settings-file) in the Azure Functions Core Tools topic.
80+
81+
* **local.settings.json**: Maintains settings used when running functions locally. These settings are not used by Azure, they are used by the [Azure Functions Core Tools](functions-run-local.md). Use this file to specify app settings for variables required by your functions. Add a new item to the **Values** array for each connection required by the functions bindings in your project. For more information, see [Local settings file](functions-run-local.md#local-settings-file) in the Azure Functions Core Tools article.
8282

8383
For more information, see [Functions class library project](functions-dotnet-class-library.md#functions-class-library-project).
8484

@@ -90,7 +90,7 @@ The Functions runtime uses an Azure Storage account internally. For all trigger
9090

9191
To set the storage account connection string:
9292

93-
1. In Visual Studio, open **Cloud Explorer**, expand **Storage Account** > **Your Storage Account**, then select **Properties** and copy the **Primary Connection String** value.
93+
1. In Visual Studio, open **Cloud Explorer**, expand **Storage Account** > **Your Storage Account**, then select **Properties** and copy the **Primary Connection String** value.
9494

9595
2. In your project, open the local.settings.json file and set the value of the **AzureWebJobsStorage** key to the connection string you copied.
9696

@@ -104,37 +104,66 @@ In pre-compiled functions, the bindings used by the function are defined by appl
104104

105105
2. Choose your trigger, set the binding properties, and click **Create**. The following example shows the settings when creating a Queue storage triggered function.
106106

107-
![](./media/functions-develop-vs/functions-vstools-create-queuetrigger.png)
108-
109-
This trigger example uses a connection string with a key named **QueueStorage**. This connection string setting must be defined in the local.settings.json file.
110-
111-
3. Examine the newly added class. You see a static **Run** method, that is attributed with the **FunctionName** attribute. This attribute indicates that the method is the entry point for the function.
107+
![Create a queue triggered function](./media/functions-develop-vs/functions-vstools-create-queuetrigger.png)
108+
109+
This trigger example uses a connection string with a key named **QueueStorage**. This connection string setting must be defined in the local.settings.json file.
110+
111+
3. Examine the newly added class. You see a static **Run** method, that is attributed with the **FunctionName** attribute. This attribute indicates that the method is the entry point for the function.
112112

113113
For example, the following C# class represents a basic Queue storage triggered function:
114114

115115
````csharp
116116
using System;
117117
using Microsoft.Azure.WebJobs;
118118
using Microsoft.Azure.WebJobs.Host;
119-
119+
120120
namespace FunctionApp1
121121
{
122122
public static class Function1
123123
{
124-
[FunctionName("QueueTriggerCSharp")]
124+
[FunctionName("QueueTriggerCSharp")]
125125
public static void Run([QueueTrigger("myqueue-items", Connection = "QueueStorage")]string myQueueItem, TraceWriter log)
126126
{
127127
log.Info($"C# Queue trigger function processed: {myQueueItem}");
128128
}
129129
}
130-
}
130+
}
131131
````
132-
133132
A binding-specific attribute is applied to each binding parameter supplied to the entry point method. The attribute takes the binding information as parameters. In the previous example, the first parameter has a **QueueTrigger** attribute applied, indicating queue triggered function. The queue name and connection string setting name are passed as parameters to the **QueueTrigger** attribute.
134133

134+
## Add bindings
135+
136+
As with triggers, input and output bindings are added to your function as binding attributes. Add bindings to a function as follows:
137+
138+
1. Make sure you have [configured the project for local development](#configure-the-project-for-local-development).
139+
140+
2. Add the appropriate NuGet extension package for the specific binding. For more information, see [Local C# development using Visual Studio](functions-triggers-bindings.md#local-csharp) in the Triggers and Bindings article. The binding-specific NuGet package requirements are found in the reference article for the binding. For an example, see the [Queue storage bindings article](functions-bindings-storage-queue.md#packages).
141+
142+
3. If there are app settings that the binding needs, add them to the **Values** collection in the [local setting file](functions-run-local.md#local-settings-file). These values are used when the function runs locally. When the function runs in the function app in Azure, the [function app settings](#function-app-settings) are used.
143+
144+
4. Add the appropriate binding attribute to the method signature. In the following example, a queue message triggers the function, and the output binding creates a new queue message with the same text in a different queue.
145+
146+
```csharp
147+
public static class SimpleExampleWithOutput
148+
{
149+
[FunctionName("CopyQueueMessage")]
150+
public static void Run(
151+
[QueueTrigger("myqueue-items-source", Connection = "AzureWebJobsStorage")] string myQueueItem,
152+
[Queue("myqueue-items-destination", Connection = "AzureWebJobsStorage")] out string myQueueItemCopy,
153+
TraceWriter log)
154+
{
155+
log.Info($"CopyQueueMessage function processed: {myQueueItem}");
156+
myQueueItemCopy = myQueueItem;
157+
}
158+
}
159+
```
160+
The connection to Queue storage is obtained from the `AzureWebJobsStorage` setting. For more information, see the reference article for the specific binding.
161+
162+
[!INCLUDE [Supported triggers and bindings](../../includes/functions-bindings.md)]
163+
135164
## Testing functions
136165

137-
Azure Functions Core Tools lets you run Azure Functions project on your local development computer. You are prompted to install these tools the first time you start a function from Visual Studio.
166+
Azure Functions Core Tools lets you run Azure Functions project on your local development computer. You are prompted to install these tools the first time you start a function from Visual Studio.
138167

139168
To test your function, press F5. If prompted, accept the request from Visual Studio to download and install Azure Functions Core (CLI) tools. You may also need to enable a firewall exception so that the tools can handle HTTP requests.
140169

@@ -148,9 +177,9 @@ To learn more about using the Azure Functions Core Tools, see [Code and test Azu
148177

149178
[!INCLUDE [Publish the project to Azure](../../includes/functions-vstools-publish.md)]
150179

151-
## Function app settings
180+
## Function app settings
152181

153-
Any settings you added in the local.settings.json must be also added to the function app in Azure. These settings are not uploaded automatically when you publish the project.
182+
Any settings you added in the local.settings.json must be also added to the function app in Azure. These settings are not uploaded automatically when you publish the project.
154183

155184
The easiest way to upload the required settings to your function app in Azure is to use the **Manage Application Settings...** link that is displayed after you successfully publish your project.
156185

@@ -172,4 +201,4 @@ For more information about Azure Functions Tools, see the Common Questions secti
172201
173202
To learn more about the Azure Functions Core Tools, see [Code and test Azure functions locally](functions-run-local.md).
174203

175-
To learn more about developing functions as .NET class libraries, see [Azure Functions C# developer reference](functions-dotnet-class-library.md). This topic also links to examples of how to use attributes to declare the various types of bindings supported by Azure Functions.
204+
To learn more about developing functions as .NET class libraries, see [Azure Functions C# developer reference](functions-dotnet-class-library.md). This article also links to examples of how to use attributes to declare the various types of bindings supported by Azure Functions.

0 commit comments

Comments
 (0)