Installing NuGet Packages in Azure Functions 2.X Runtime (PREVIEW)


Note: The 2.X version is currently in a preview phase so please bare in mind that this could be no longer valid eventually.

Hi folks,

In the current version of the Azure Functions Runtime (1.x) we are able to install NuGet packages for our C# and F# functions. The way to do it is adding the dependencies to a file named project.json. As you may be thinking this is because when the 1.x version was designed all was about project.json files. There's a really good documentation page where you can read about it: https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp 

During the development of the .NET Core tooling there was a design change, no longer supporting the project.json project files and instead moving the project system files to a XML ones, which is the MSBuild supported way. In the new version of the runtime we can find this design change as well. You can find the differences about both systems here: https://docs.microsoft.com/en-us/dotnet/core/tools/project-json-to-csproj

Adding NuGet Packages to the Function

As we would do with the 1.X, we need to create a file within our function folder to define the function's dependencies. Since we're using the new project system here the file name needs to be function.proj.

In the file, inside an ItemGroup section, we will be adding the PackageReference items with the package and the version. For example here I'm installing Microsoft.Azure.Devices 1.5 and Newtonsoft.Json 10:

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Devices" Version="1.5.0"/>
    <PackageReference Include="Newtonsoft.Json" Version="10.0.3"/>
  </ItemGroup>

</Project>

Then just save the file if you're editing it from the portal and the Azure Functions Runtime will install your dependencies and compile your function.

May the PaaS  Serverless be with you!

Carlos

Comments (0)

Skip to main content