Visual Studio Online C#

Use the tools you love

Connect to your codespaces from your browser or Visual Studio Code.

Connect to your codespaces from your browser or Visual Studio Code. Simplify your workflow. Automatically set up dependencies and SSH keys. Go from code to commit faster on any project. Extend and customize. Configure your editor with dotfiles and extensions to create a consistent environment in every codespace. Test your C# code online with.NET Fiddle code editor.

Simplify your workflow

Automatically set up dependencies and SSH keys. Go from code to commit faster on any project.

Extend and customize

Configure your editor with dotfiles and extensions to create a consistent environment in every codespace.

With your development in the cloud, you can contribute code from any device.

Contribute to projects without complicating your local setup. Spin up dev environments with a click—even for projects you haven't worked on before—and switch between them with ease.

Codespaces is available in beta. Add yourself to our early-access list to be one of the first to use it.

Request early access

Is Codespaces available to everyone?

Visual studio download

Codespaces will be available to a small group of GitHub users while in limited beta. Over time, more users will have access to the beta based on availability and sign up date.

How do I start using Codespaces?

If you’re in the Codespaces beta, you’ll see a “Code” button in the Code tab of all supported repositories.

Is Codespaces available for all repositories?

While in limited beta, Codespaces will be available for repositories you own and public repositories. Additional support will be available as the beta progresses, but for now, Codespaces will not be available for private repositories that belong to organizations.

Can I leave a codespace open?

When you create a codespace, you can leave it open for as long as you wish but it will suspend automatically after 30 minutes of inactivity. You can reconnect at any time through Codespaces in the browser or VS Code.

Visual Studio Online C#

What if I don’t want to develop in a browser?

If you prefer, you can open a codespace in GitHub and then connect to it in VS Code.

How much does Codespaces cost?

For more about Codespaces pricing, see our documentation. Codespaces is free during the limited beta.

How is Codespaces different from VS Code?

Codespaces sets up a cloud-hosted, containerized, and customizable VS Code environment. After set up, you can connect to a codespace through the browser or through VS Code.

How can I configure a codespace?

Inside of a codespace, you’ll have access to the Visual Studio Code Marketplace, and you can preload any extensions you want loaded at launch using a devcontainer configuration file. You can also personalize your codespace by pulling in dotfiles.

-->

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

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

Visual Studio Online Compiler C#

Visual studio download

Prerequisites

To complete this tutorial, first install Visual Studio 2019. Ensure you select the Azure development workload during installation. If you want to create an Azure Functions project by using Visual Studio 2017 instead, you must first install the latest Azure Functions tools.

If you don't have an Azure subscription, create a free account before you begin.

Create a function app project

The Azure Functions project template in Visual Studio creates a project that you can publish to a function app in Azure. You can use a function app to group functions as a logical unit for easier management, deployment, scaling, and sharing of resources.

  1. From the Visual Studio menu, select File > New > Project.

  2. In Create a new project, enter functions in the search box, choose the Azure Functions template, and then select Next.

  3. In Configure your new project, enter a Project name for your project, and then select Create. The function app name must be valid as a C# namespace, so don't use underscores, hyphens, or any other nonalphanumeric characters.

  4. For the Create a new Azure Functions application settings, use the values in the following table:

    SettingValueDescription
    Functions runtimeAzure Functions v3
    (.NET Core)
    This value creates a function project that uses the version 3.x runtime of Azure Functions, which supports .NET Core 3.x. Azure Functions 1.x supports the .NET Framework. For more information, see Azure Functions runtime versions overview.
    Function templateHTTP triggerThis value creates a function triggered by an HTTP request.
    Storage account (AzureWebJobsStorage)Storage emulatorBecause an Azure Function requires a storage account, one is assigned or created when you publish your project to Azure. An HTTP trigger doesn't use an Azure Storage account connection string; all other trigger types require a valid Azure Storage account connection string.
    Authorization levelAnonymousThe created function can be triggered by any client without providing a key. This authorization setting makes it easy to test your new function. For more information about keys and authorization, see Authorization keys and HTTP and webhook bindings.

    Make sure you set the Authorization level to Anonymous. If you choose the default level of Function, you're required to present the function key in requests to access your function endpoint.

  5. Select Create to create the function project and HTTP trigger function.

C++ Online

Visual Studio creates a project and class that contains boilerplate code for the HTTP trigger function type. The boilerplate code sends an HTTP response that includes a value from the request body or query string. The HttpTrigger attribute specifies that the function is triggered by an HTTP request.

Rename the function

The FunctionName method attribute sets the name of the function, which by default is generated as Function1. Since the tooling doesn't let you override the default function name when you create your project, take a minute to create a better name for the function class, file, and metadata.

Online Visual Studio Code

  1. In File Explorer, right-click the Function1.cs file and rename it to HttpExample.cs.

  2. In the code, rename the Function1 class to `HttpExample'.

  3. In the HttpTrigger method named Run, rename the FunctionName method attribute to HttpExample.

Visual Studio Online Api C#

Now that you've renamed the function, you can test it on your local computer.

Run the function locally

Visual Studio integrates with Azure Functions Core Tools so that you can test your functions locally using the full Azure Functions runtime.

  1. To run your function, press F5 in Visual Studio. You might need to enable a firewall exception so that the tools can handle HTTP requests. Authorization levels are never enforced when you run a function locally.

  2. Copy the URL of your function from the Azure Functions runtime output.

  3. Paste the URL for the HTTP request into your browser's address bar. Append the query string ?name=<YOUR_NAME> to this URL and run the request. The following image shows the response in the browser to the local GET request returned by the function:

  4. To stop debugging, press Shift+F5 in Visual Studio.

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

Publish the project to Azure

Before you can publish your project, you must have a function app in your Azure subscription. Visual Studio publishing creates a function app for you the first time you publish your project.

  1. In Solution Explorer, right-click the project and select Publish and in Target, select Azure then Next.

  2. For the Specific target, choose Azure Function App (Windows), which creates a function app that runs on Windows.

  3. In Function Instance, choose Create a new Azure Function...

  4. Create a new instance using the values specified in the following table:

    SettingValueDescription
    NameGlobally unique nameName that uniquely identifies your new function app. Accept this name or enter a new name. Valid characters are: a-z, 0-9, and -.
    SubscriptionYour subscriptionThe Azure subscription to use. Accept this subscription or select a new one from the drop-down list.
    Resource groupName of your resource groupThe resource group in which to create your function app. Select an existing resource group from the drop-down list or choose New to create a new resource group.
    Plan TypeConsumptionWhen you publish your project to a function app that runs in a Consumption plan, you pay only for executions of your functions app. Other hosting plans incur higher costs.
    LocationLocation of the app serviceChoose a Location in a region near you or other services your functions access.
    Azure StorageGeneral-purpose storage accountAn Azure Storage account is required by the Functions runtime. Select New to configure a general-purpose storage account. You can also choose an existing account that meets the storage account requirements.
  5. Select Create to create a function app and its related resources in Azure. Status of resource creation is shown in the lower left of the window.

  6. Back in Functions instance, make sure that Run from package file is checked. Your function app is deployed using Zip Deploy with Run-From-Package mode enabled. This is the recommended deployment method for your functions project, since it results in better performance.

  7. Select Finish, and on the Publish page, select Publish to deploy the package containing your project files to your new function app in Azure.

    After the deployment completes the root URL of the function app in Azure is shown in the Publish tab.

  8. In the Publish tab, choose Manage in Cloud Explorer. This opens the new function app Azure resource in Cloud Explorer.

    Cloud Explorer lets you use Visual Studio to view the contents of the site, start and stop the function app, and browse directly to function app resources on Azure and in the Azure portal.

Test your function in Azure

  1. In Cloud Explorer, your new function app should be selected. If not, expand your subscription > App Services, and select your new function app.

  2. Right-click the function app and choose Open in Browser. This opens the root of your function app in your default web browser and displays the page that indicates your function app is running.

  3. In the address bar in the browser, append the string /api/HttpExample?name=Functions to the base URL and run the request.

    The URL that calls your HTTP trigger function is in the following format:

    http://<APP_NAME>.azurewebsites.net/api/HttpExample?name=Functions

  4. Go to this URL and you see a response in the browser to the remote GET request returned by the function, which looks like the following example:

Clean up resources

Other quickstarts in this collection build upon this quickstart. If you plan to work with subsequent quickstarts, tutorials, or with any of the services you have created in this quickstart, do not clean up the resources.

Resources in Azure refer to function apps, functions, storage accounts, and so forth. They're grouped into resource groups, and you can delete everything in a group by deleting the group.

You created resources to complete these quickstarts. You may be billed for these resources, depending on your account status and service pricing. If you don't need the resources anymore, here's how to delete them:

  1. In the Cloud Explorer, expand your subscription > App Services, right-click your function app, and choose Open in Portal.

  2. In the function app page, select the Overview tab and then select the link under Resource group.

  3. In the Resource group page, review the list of included resources, and verify that they're the ones you want to delete.

  4. Select Delete resource group, and follow the instructions.

    Deletion may take a couple of minutes. When it's done, a notification appears for a few seconds. You can also select the bell icon at the top of the page to view the notification.

C# Learning Online Visual Studio

Next steps

In this quickstart, you used Visual Studio to create and publish a C# function app in Azure with a simple HTTP trigger function.

Visual Studio Online C# Compiler

Advance to the next article to learn how to add an Azure Storage queue binding to your function: