Most .NET developers make heavy use of the NuGet packages repository to leverage libraries implemented by Microsoft and third-party providers. The process of adding dependencies on external libraries in C# script-based functions is different from a traditional .NET application.
There are the following two ways to reference an external assembly in a C# script-based function:
- Using an
#r
directive - Adding a reference in the
project.json
file
Let us explore both options in more detail.
To reference framework assemblies and a number of other commonly used assemblies, you can use the #r
AssemblyName directive.
For instance, a Newtonsoft.Json
library that we have used in the ScoreTweet
function is one of the common libraries that can be referenced with an #r
directive. If we were to deploy ScoreTweet
as a C# script-based function, we would need to add the following line before the function code:
#r "Newtonsoft.Json"
The full function code using the ...