Azure Functions App V2 Using C# (.NET Core)

Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. You can write just the code you need for the problem at hand, without worrying about a whole application or the infrastructure to run it. Functions can make development even more productive, and you can use a development language of choice, such as C#, F#, Node.js, Java, or PHP. Pay only for the time your code runs and trust Azure to scale as needed. Azure Functions lets you develop serverless applications on Microsoft Azure.
In this article, we will be creating and running Azure Functions. I will also explain how to install NuGet packages. Before proceeding, you must have an active Azure subscription. Let's begin step by step.
Step 1 
Open Azure portal. Click on "Create a resource" and search "Function App".
Step 2 
Enter all the fields. Make sure to select .NET in Runtime stack option.
Azure Function App V2 Using C# (.NET Core)
Once your Functions app is created successfully, you can find your app in your resource group. Navigate to your resource group and click on your Functions app.
Azure Function App V2 Using C# (.NET Core) 
The status of your Functions app will be running if it is deployed properly. 
Step 3 
Click on "+" icon on "Functions" under demo121212.
Azure Function App V2 Using C# (.NET Core) 
Step 4
Select the In-Portal option (We will create the Functions on the portal, but we can do the same from VS, VS Code).
Select "More templates". We can see all the available triggers for Azure Functions. For now, we will use HttpTrigger, which means whenever our app will receive an HTTP request, it is executed. 
Step 5 
In this step, we will be naming our Azure Functions app and its authorization level. I have kept the name default one, and authorization level as Anonymous.
Azure Function App V2 Using C# (.NET Core) 
On successful creation of the function, we can see it under Functions. Click on the newly created function (HttpTrigger1). The entry point for our function is the Run method, which is in the run.csx file. 
Step 6
  • Click on "Log" at the button, it will open the log terminal. All our function outputs and logs will be displayed in this terminal. 
  • Now click on the "Run" button. Our function we start executing and we can see the output in the log terminal. 
Perfect!. We have successfully created an Azure function. 
Now, let's add a few NuGet packages and try to run it again. 
Step 7
To install the NuGet package, we need to create a file with name "function.proj" and add all the dependencies inside it. 
Let us now create a file called "function.proj" in your local system ( like desktop).

Copy and paste the below code inside it and save the file. 
  1. <Project Sdk="Microsoft.NET.Sdk">  
  2.     <PropertyGroup>  
  3.         <TargetFramework>netstandard2.0</TargetFramework>  
  4.     </PropertyGroup>  
  5.     <ItemGroup>  
  6.         <PackageReference Include="Microsoft.Extensions.Caching.Redis" Version="2.1.2" />  
  7.     </ItemGroup>  
  8. </Project>  

Since we are working with Azure function V2 (.NET Core), our targetframework is "netstandard2.0". If you are working with Azure function V1 (.NET framework), then targetframework would be "net46". 

Step 8
  • Go to your function on the portal. On the right panel, click on "View files". 
  • Upload this function.proj file. 
  • Click "Save", to save your function app.
In log terminal, you will see that your function started to compile. On successful compiling, it will generate a file called "project.assets.json".
Step 9
Go ahead and use your NuGet package with the "using" keyword. 
Azure Function App V2 Using C# (.NET Core) 
Please share your valuable feedback. 
Thank you for reading.