Adding NuGet packages to Azure Functions
With Azure Functions, your limitations are tight with the programming language you use. The code gives you the maximum flexibility in terms of functionality you want to create in function. Hosting and scaling are taken care of the Azure platform (App Service).
You can enhance Azure Functions by importing one or more NuGet packages to your project in Visual Studio or when you use the in-portal experience you need to do the following:
• create a file with name ’function.proj.’;
• add all the dependencies you need in it.
You proj file can look like:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netstandard2.0</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.Azure.Cosmos" Version="3.0.0" /> </ItemGroup> </Project>
Upon saving this file, you should see the console update stating that the packages are getting installed. Next, you reference the package with a using statement.
Within Visual Studio, adding NuGet packages is easier; expand your dependencies, right-click and choose the option ‘Manage NuGet Packages’. The NuGet Package dialogue will appear, and you can select any Nuget package you want to install for your Azure Function.
Either way leveraging NuGet packages in your Azure Function enables you to enhance your functions and make them more powerful.
Explore how Serverless360 could help manage and monitor your applications involving Azure Functions.