Skip to content

Latest commit

 

History

History
132 lines (83 loc) · 7.54 KB

create-first-function-vs-code-csharp.md

File metadata and controls

132 lines (83 loc) · 7.54 KB
title description ms.topic ms.date ms.custom adobe-target adobe-target-activity adobe-target-experience adobe-target-content
Create a C# function using Visual Studio Code - Azure Functions
Learn how to create a C# function, then publish the local project to serverless hosting in Azure Functions using the Azure Functions extension in Visual Studio Code.
quickstart
08/15/2021
devx-track-csharp
true
DocsExp–386541–A/B–Enhanced-Readability-Quickstarts–2.19.2021
Experience B
./create-first-function-vs-code-csharp-ieux

Quickstart: Create a C# function in Azure using Visual Studio Code

[!INCLUDE functions-language-selector-quickstart-vs-code]

In this article, you use Visual Studio Code to create a C# function that responds to HTTP requests. After testing the code locally, you deploy it to the serverless environment of Azure Functions.

This article supports creating both types of compiled C# functions:

Completing this quickstart incurs a small cost of a few USD cents or less in your Azure account.

There's also a CLI-based version of this article.

Configure your environment

Before you get started, make sure you have the following requirements in place:


Create your local project

In this section, you use Visual Studio Code to create a local Azure Functions project in C#. Later in this article, you'll publish your function code to Azure.

  1. Choose the Azure icon in the Activity bar, then in the Azure: Functions area, select the Create new project... icon.

    Choose Create a new project

  2. Choose a directory location for your project workspace and choose Select.

    [!NOTE] These steps were designed to be completed outside of a workspace. In this case, do not select a project folder that is part of a workspace.

  3. Provide the following information at the prompts:

    Prompt Selection
    Select a language for your function project Choose C#.
    Select a .NET runtime Choose .NET Core 3.1 LTS.
    Select a template for your project's first function Choose HTTP trigger.
    Provide a function name Type HttpExample.
    Provide a namespace Type My.Functions.
    Authorization level Choose Anonymous, which enables anyone to call your function endpoint. To learn about authorization level, see Authorization keys.
    Select how you would like to open your project Choose Add to workspace.
    Prompt Selection
    Select a language for your function project Choose C#.
    Select a .NET runtime Choose .NET 5.0 Isolated.
    Select a template for your project's first function Choose HTTP trigger.
    Provide a function name Type HttpExample.
    Provide a namespace Type My.Functions.
    Authorization level Choose Anonymous, which enables anyone to call your function endpoint. To learn about authorization level, see Authorization keys.
    Select how you would like to open your project Choose Add to workspace.

  4. Using this information, Visual Studio Code generates an Azure Functions project with an HTTP trigger. You can view the local project files in the Explorer. To learn more about files that are created, see Generated project files.

[!INCLUDE functions-run-function-test-local-vs-code-csharp]

After you've verified that the function runs correctly on your local computer, it's time to use Visual Studio Code to publish the project directly to Azure.

[!INCLUDE functions-sign-in-vs-code]

[!INCLUDE functions-publish-project-vscode]

[!INCLUDE functions-vs-code-run-remote]

[!INCLUDE functions-cleanup-resources-vs-code.md]

Next steps

You have used Visual Studio Code to create a function app with a simple HTTP-triggered function. In the next article, you expand that function by connecting to either Azure Cosmos DB or Azure Queue Storage. To learn more about connecting to other Azure services, see Add bindings to an existing function in Azure Functions.

[!div class="nextstepaction"] Connect to Azure Cosmos DB Connect to Azure Queue Storage

[!div class="nextstepaction"] Connect to Azure Cosmos DB Connect to Azure Queue Storage