How To Deploy An Azure Function App Using Visual Studio
Tags: serverless, azure, csharp, beginners
Published: 2023-06-10 15:45:03

Hello there! I will be walking you through how to create an Azure Function App and publish to Azure portal using Visual Studio.

Also, we would be creating and deploying a calculator app. So, sit back, follow through and enjoy the learning journey.

### **Prerequisites**

- Visual Studio Community with .Net Development workload (Click [here](https://visualstudio.microsoft.com/vs/community/) to download).

- [Azure](https://portal.azure.com/#home) Account (Click [here](https://azure.microsoft.com/en-us/free/) to register if you don't have an account or proceed to sign in).
**Note:** The interface of my Visual Studio might be different from yours as I am on a Mac, but the processes are almost the same with only slight difference.

Now that you have all the requirements, let's proceed to creating our function app.

**Step 1:** Log in to Azure Portal, Search for "Function App" in the search box and click on "Create".
![Function App interface](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xpd6529juxbap4h5hj6b.png)
**Step 2a:** Fill out the necessary fields.
![Setting up Function App](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tbyi3saee8x4uvjw3gl8.png)**Note:** Steps 2a and 2b can be completed in one step. I divided mine into two in order to capture the whole fields.

- For _**resource group**_, You can create a new resource group by clicking the "**create new**" or you can choose a previously created resource group. I called mine "**my resources**". You can choose to call yours whatever name you desire.

- "**Function App Name**" is also random. I chose "**Blog-Calculator-App**".

- Select "**Code**" as against "**Container Image**".

- Select "**.Net**" as your runtime stack. It will automatically choose the **version** and **region** for you.

**Step 2b:** Choose your preferred operating system and use the default hosting option. Then click on "**Review + Create**".
![Function App Interface](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c1lnqg6aoo7ot8lo2114.png)At this point, you may want to grab a pop corn while it finishes deploying.

**Step 3a:** Open Visual Studio and click on "**New**".
![Visual Studio Interface](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o7tgysoop61tmnsckvz0.png)
**Step 3b:** Click on "**General**" under "**Cloud**". Then select "**Azure Functions**" and click on "**Continue**".
![Choosing Azure Functions in Visual Studio](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9st7wb4iqt62ershd4r8.png)
**Step 3c:** On the side side pane, select "**Http trigger**", give your function app a name and click on "**Continue**".
![Giving your function app a name and choosing http trigger](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pyfefunvja7fzcmyaifn.png)The reason for choosing "**Http trigger**" is so that we could test it over the web or browser.

**Step 3d:** Go ahead and click on "**Create**".
![Creating a function app](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jk0gpr1yp1gnfqe3e6gk.png)
**Step 4:** Replace the codes from line 13 to line 34 with this:
public static class Sum
    {
        [FunctionName("Sum")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");
            int x = int.Parse(req.Query["x"]);
            int y = int.Parse(req.Query["y"]);
            int result = x + y;
            return new OkObjectResult(result);
        }
    }
![Calculator App Interface](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cnit1qgzvuye2wa5lcav.png)
**Step 5:** Click on "**Build**" at the top of your IDE. Then click  on "**Build Solution**".
![Building your app](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wvhxogrkft3n2l87f94a.png)Ensure your application builds successfully.

**Step 6:** Click on "Build" and then "Publish to Azure". Then Proceed to sign in with your Azure credentials.
![Publishing to Azure from Visual Studio](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0895rlz7zn8f83qava95.png)
**Step 7:** You would see a list of your resource groups and services. Choose the one that matches the Function App name you created on Azure Portal. Then click on "**Publish**".
![Publishing to Azure](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ei9kg1wz8sfl93o5hhy8.png)
Wait for it to finish publishing. If it's successful you should see something like this in your browser
![Function App is up and running](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e2elc5agoazezbounq8s.png)
**Step 9:** Go back to Azure Portal and click on the function app you created earlier. On the left pane click on "**Functions**".
![Function App overview](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x1nupajedmdzcfrcjxf7.png)You should be able to see the function we just published with the name "**Sum**".

**Step 10:** Click on **Sum**, then click on "**Get Function Url**". Copy the Url.
![Get Function Url](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m6u29d82svipmel1vxfl.png)
**Step 11:** Paste the Url in any browser of your choice, append the values of x and y to the Url, click enter to know if the sum function is working perfectly.
![Sum of x and y](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gy713n2rxoej700ruoe6.png)Notice how I appended the values of x and y to the Url.

There you have it. You have successfully published a Function App using Visual Studio to Azure portal, and you have tested it using http.

Connect with me
LinkedIn: https://www.linkedin.com/in/chisom-amadi/
GitHub: https://github.com/tchisom17