0
votes

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.

2

2 Answers

1
votes

It seems that references in .net core using VS 2019 are a little flaky. While having this issue Microsoft released EF Core 3.1.1. I decided to update the EF Core 3.1.0 package I was referencing to EF Core 3.1.1 using nuget. When I did this I started to get all kinds of errors around missing references. At this point, I believed something was wrong locally so I checked my code into Azure Dev Ops to see if our gated build would fail or not. IT DID NOT! At this point, I deleted all the code from my local machine and got the latest from Azure Dev Ops. When I tried building it complained of a missing file "project.assets.json" and told me to do a "dotnet restore". I opened up the package manager and did just that. Once it completed without issues all my references were fixed including my transitive reference issue with my azure function!

0
votes

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.