LaVOZs

The World’s Largest Online Community for Developers

'; c# - .NET Core 3.1 Transitive Reference Issue With Azure Function Class Library - LavOzs.Com

I have a solution with 5 .NET Core 3.1 projects in Visual Studio 2019 16.4.3 with the following structure and references:

MyProject.Core (Class Library)

  • Project Reference to MyProject.SharedKernel

MyProject.Infrastructure (Class Library)

  • Project Reference to MyProject.Core

MyProject.SharedKernel (Class Library)

  • EnsureThat NuGet Package Reference

MyProject.Function (Azure Function v3 Class Library)

  • Project Reference to MyProject.Core
  • Project Reference to MyProject.SharedKernel
  • Project Reference to MyProject.Infrastructure

MyProject.Web (ASP.NET Core 3.1)

  • Project Reference to MyProject.Core
  • Project Reference to MyProject.SharedKernel
  • Project Reference to MyProject.Infrastructure

From MyProject.Web I am able to use the EnsureThat library with no issues because if references MyProject.SharedKernel which in turn has the reference to the EnsureThat NuGet package. For some reason, I am unable to do the same in the MyProject.Function project even though it has the exact same reference to MyProject.SharedKernel.

Is there something about an azure function class library that prevents transitive references from working properly? I would prefer not to have to also install the EnsureThat NuGet package in the MyProject.Function project directly.

Unfortunately, what you want is impossible. This is no matter with VS 2019, the reason is this feature has not yet been implemented.

Azure Function can not reference Class Library now. But you can reference the dll file of your class library, the means you can make an output in your SharedKernel Class library and get the output in your azure function.

First, build the SharedKernel Class library, then reference to the dll of this.

enter image description here

enter image description here

In your azure function:

enter image description here

By the way, you can only use the output, using Ensure That package is still impossible. You need to install it in your azure function.

Hope it helps.

Related
How do I reference a multi-target .NET Core class library from a 4.6.1 project within the same solution?
Can you reference a .NET Core class library from a regular c# Class Library?
Reference c# class library in my Azure Function
What is the difference between .NET Core and .NET Standard Class Library project types?
How to include a library in .NET Core 2.0
Azure function with .net core 2 class library
.NET Core Azure Function missing reference
Azure Function .net framework