Adding NuGet packages to Azure Functions
  • 03 Apr 2022
  • 1 Minute to read
  • Contributors
  • Comments
  • Dark
    Light
  • PDF

Adding NuGet packages to Azure Functions

  • Comments
  • Dark
    Light
  • PDF

#ServerlessTips - Azure Functions
Author: Steef-Jan Wiggers Azure MVP

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>  

libraries-nuget

When working with Azure Function version 2.x, the target framework is ‘netstandard2.0’.

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.

Azure-functions.png

A support platform engineered for your Microsoft Azure Resources

Explore how Serverless360 could help manage and monitor your applications involving Azure Functions.


Was this article helpful?