In this article we will see how to refer nuget package in your azure function v2.x. Please make sure that your Azure function is version 2, because nuget package is referred differently in version 1 please refer my other article for v1.x – How to refer nuget package in Azure Function v1.x. To check your current azure function version, please follow the below step.
Go to Azure Portal (https://portal.azure.com/ ) -> open Function App, under Overview or Platform features tab there will be link Function app settings
In my function app, I’ve already created a simple HttpTrigger function as you can see from below screenshot
Now, I want to add the following nuget package – https://www.nuget.org/packages/SharePointPnPCoreOnline/ to my azure function, to do that we need to create a File called function.proj (but in v1.x this file name should be project.json)
paste the below XML in newly created function.proj file
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netstandard2.0</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="SharePointPnPCoreOnline" Version="3.2.1810"/> </ItemGroup> </Project>
And click on Save, if you need more than one nuget package to be installed, then please add another <PackageReference Include=”package-name ” Version=”version-num”/>
inside <ItemGroup> tag.
Once it’s saved, you can see from the log that the package is getting installed
After installation is over (it takes few seconds based on size of the package), I just referred Microsoft.SharePoint.Client dll to check and it worked.