In this article we will see how to refer nuget package in Azure Function version 1.x. Please make sure that your Azure function is version 1, because nuget package is referenced in different way in version 2. 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 Under Runtime version
Adding NuGet package from Azure Portal:
Here we’re adding nuget package to azure function from azure portal. To achieve this, create a file called project.json in your azure function and paste the following json value, inside dependencies, specify the nuget package name and its version
For example, I’ve added SharePointPnPCoreOnline nuget package with the version 2.24.1803 and save the project.json file
After click on save, we can see from the logs that it will start installing all dependencies,
It will take few seconds based on the size of the nuget package,
And to utilize nuget package no need to use #r in the code, we can directly start using. Well in this example, I am not doing anything further other than referring nuget package, so I just utilized ClientContext class from Microsoft.SharePoint.Client dll to show it got referred without issue. Thank you for reading
Adding Nuget package from Visual Studio
If an azure function is created from Visual Studio (Create And Debug Azure Function Using Visual Studio 2017 – Part 1) then it’s very easy to add Nuget package, just like how we add reference in other project in VS
Once the project is published, all the dependencies will be added to bin folder.