14

Is it possible to reference a c# class library in an Azure Function visual studio project?

I am aware of the possibilities to reference external libraries and Nuget packages. Currently I am using shared .csx files as described here. These .csx files now contain a copy of my DTO's which are also used in the Service Agents which I use to consume the functions.

Ideally I want to add a reference in Visual Studio from a Function to a class library project and that Visual Studio is adding this dll to the bin folder.

2 Answers 2

10

Currently, project references are not supported, but you can have the output of your project (the resulting assembly and possible dependencies) copied onto a folder under your function's root, which you can then leverage using the external libraries support you've mentioned above (e.g. #r "..\myassemblyfolder\MyAssembly.dll")

If possible, I'd suggest opening an issue with that feature request, sharing more about your scenario on this repository. This allows other people to upvote those requests and helps the team prioritize this work.

Sign up to request clarification or add additional context in comments.

4 Comments

Please add to this GitHub issue: github.com/Azure/Azure-Functions/issues/90
Wow. Not being able to add-reference is a "one step forward, two steps back" scenario IMHO. Seems like the most need in reusing any code. Thanks for the workaround.
@granadaCoder this scenario is now supported by the pre-compiled model. You can find more information about the tooling support here: blogs.msdn.microsoft.com/webdev/2017/05/10/…
Or you can create API and call that API from Azure Function.
-2

Previously this was not possible. This is now possible as you can read here: https://learn.microsoft.com/en-us/azure/azure-functions/functions-dotnet-class-library.


Old answer:

This is now possible by using the new Visual Studio 2017 Tools for Azure Functions.

You can get more information about this in the following links:

4 Comments

Just curious if you could elaborate. I have the most up-to-date Azure Functions tools, and it still does not appear possible to reference other projects from the Function App project. I'm afraid that Function Apps might require all code to be within the same project.
Never mind. My issues involved .NET version targeting, and having to jury-rig a reference to Newtonsoft.JSON 11.x (a dependency of one of my class libraries) amid the Function App's own reference to version 9.x.
I am using Visual Studio 2019 and still Azure Function does not support that.
First link returns 404 and the second one has nothing to do with referencing c# library in azure function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.