DEV Community

Cover image for From Local to Cloud: Building & Deploying C# Azure Functions in VS Code
Olalekan Oladiran
Olalekan Oladiran

Posted on

From Local to Cloud: Building & Deploying C# Azure Functions in VS Code

Introduction

Azure Functions let you run event-driven code without managing infrastructure—perfect for APIs, file processing, and automation. In this step-by-step guide, you’ll learn how to:

  • Develop locally in C# with VS Code
  • Test thoroughly using the Azure Functions Core Tools emulator
  • Deploy seamlessly to the cloud with built-in CI/CD
  • Validate execution in both local and Azure environments Whether you’re building microservices or backend APIs, this tutorial equips you with a production-ready workflow using .NET 8’s isolated process model.

Requirements

Setting Up Your Local Project

Purpose: Create a foundation for your serverless function before deploying to Azure.

  • In Visual Studio Code, press F1 to open the command palette and search for and run the command Azure Functions: Create New Project.... Image description Image description
  • Select the directory location for your project workspace and choose Select. You should either create a new folder or choose an empty folder for the project workspace. Don't choose a project folder that is already part of a workspace. Image description Image description
  • Provide the following information at the prompts: Prompt Action
    • Select the folder that will contain your function projects Select Browse... to select a folder for you app.
    • Select a language Select C#. Image description
    • Select a .NET runtime Select .NET 8.0 Isolated Image description
    • Select a template for your project's first function Select HTTP trigger.1 Image description
    • Provide a function name Enter HttpExample. Image description
    • Provide a namespace Enter My.Function. Image description
    • Authorization level Select Anonymous, which enables anyone to call your function endpoint. Image description Image description Depending on your VS Code settings, you might need to use the Change template filter option to see the full list of templates.
  • Visual Studio Code uses the provided information and generates an Azure Functions project with an HTTP trigger. You can view the local project files in the Explorer. Image description

Local Testing

  • Make sure the terminal is open in Visual Studio Code. You can open the terminal by selecting Terminal and then New Terminal in the menu bar.
  • Switch to Run and Debug, click on start debugging. Image description
  • Output from Core Tools is displayed in the Terminal panel. Your app starts in the Terminal panel. You can see the URL endpoint of your HTTP-triggered function running locally. Image description
  • With Core Tools running, go to the Azure: Functions area. Under Functions, expand Local Project > Functions. Right-click the HttpExample function and select Execute Function Now.... Image description
  • In Enter request body type the request message body value of { "name": "Azure" }. Press Enter to send this request message to your function. When the function executes locally and returns a response, a notification is raised in Visual Studio Code. Image description
  • select the notification bell icon to view the notification. Information about the function execution is shown in Terminal panel. Image description
  • Press control + C to stop Core Tools and disconnect the debugger. After verifying that the function runs correctly on your local computer, it's time to use Visual Studio Code to publish the project directly to Azure.

Deploy and execute the function in Azure

In this section you create an Azure Function App resource and deploy the function to the resource.

Sign in to Azure

Before you can publish your app, you must sign in to Azure. If you already signed in, go to the next section.

  • If you aren't already signed in, choose the Azure icon in the Activity bar, then in the Azure: Functions area, choose Sign in to Azure.... Image description
  • When prompted in the browser, choose your Azure account and sign in using your Azure account credentials.
  • After successfully signing in, you can close the new browser window. The subscriptions that belong to your Azure account are displayed in the Side bar.

Create resources in Azure

In this section, you create the Azure resources you need to deploy your local function app.

  • Choose the Azure icon in the Activity bar, then in the Resources area select the Create resource... button.
  • Provide the following information at the prompts:
    Prompt Action
    Select a resource to create Select Create Function App in Azure...
    Image description
    Select subscription Select the subscription to use. You won't see this if you only have one subscription.
    Image description
    Enter a globally unique name for the function app Type a name that is valid in a URL path, for example myfunctionappola. The name you type is validated to make sure that it's unique.
    Image description
    Select a location for new resources For better performance, select a region near you.
    Image description
    Select a runtime stack Select .NET 8.0 Isolated.
    Image description
    Select resource authentication type Select Secrets
    Image description
    The extension shows the status of individual resources as they're being created in the AZURE area of the terminal window.
    Image description

  • When completed, the following Azure resources are created in your subscription, using names based on your function app name:

    • A resource group, which is a logical container for related resources.
    • A standard Azure Storage account, which maintains state and other information about your projects.
    • A Flex consumption plan, which defines the underlying host for your serverless function app.
    • A function app, which provides the environment for executing your function code. A function app lets you group functions as a logical unit for easier management, deployment, and sharing of resources within the same hosting plan.
    • An Application Insights instance connected to the function app, which tracks usage of your serverless function.

Deploy the project to Azure

  • In the command palette, search for and run the command Azure Functions: Deploy to Function App.... Image description
  • Select the subscription you used when creating the resources. Image description
  • Select the function app you created. When prompted about overwriting previous deployments, select Deploy to deploy your function code to the new function app resource. Image description
  • After deployment completes, select View Output to view the details of the deployment results. If you miss the notification, select the notification bell icon in the lower right corner to see it again. Image description Image description

Run the function in Azure

  • Back in the Resources area in the side bar, expand your subscription, your new function app, and Functions. Right-click the HttpExample function and choose Execute Function Now.... Image description Image description Image description Image description
  • In Enter request body you see the request message body value of { "name": "Azure" }. Press Enter to send this request message to your function. Image description
  • When the function executes in Azure and returns a response, a notification is raised in Visual Studio Code. select the notification bell icon to view the notification. Image description

Thanks for staying till the end

Top comments (0)