How can we import C# Class in azure function from the external repos?

Suman Gautam 0 Reputation points
2023-03-16T16:24:48.7033333+00:00

Can we create the object of the external class in the azure function to use its functionality?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,208 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Sudipta Chakraborty - MSFT 1,096 Reputation points Microsoft Employee
    2023-03-16T19:05:42.0766667+00:00

    You can define classes in separate files and reference those files using the #load directive as documented here: https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp?tabs=functionsv2#reusing-csx-code.

    You can also reference an assembly where your classes are defined and is documented here: https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp?tabs=functionsv2#referencing-external-assemblies

    0 comments No comments

  2. MuthuKumaranMurugaachari-MSFT 22,136 Reputation points
    2023-03-23T15:30:39.4833333+00:00

    Suman Gautam Thanks for posting your question in Microsoft Q&A. I assume, external repos as public NuGet Packages or private feed. You can specify packageSources in the project reference other than public NuGet feed.

    For C# script, refer Using NuGet packages doc to add external packages in *.csproj file and follow the steps shared by Sudipta to reference the files/objects. In Isolated model, you can add packageSources in Nuget.Config and package references in *.csproj file and import packages with using statement and the same goes with In process model as well (similar discussion: SO Thread).

    Samples for Isolated process samples are available here and other samples here. I hope this helps with your question and feel free to add a comment with additional details if you face issues.


    If you found the answer to your question helpful, please take a moment to mark it as "Yes" for others to benefit from your experience.

    0 comments No comments