简体   繁体   English

Azure 函数类库的 .NET Core 3.1 传递引用问题

[英].NET Core 3.1 Transitive Reference Issue With Azure Function Class Library

I have a solution with 5 .NET Core 3.1 projects in Visual Studio 2019 16.4.3 with the following structure and references:我在 Visual Studio 2019 16.4.3 中有 5 个 .NET Core 3.1 项目的解决方案,其结构和参考如下:

MyProject.Core (Class Library) MyProject.Core(类库)

  • Project Reference to MyProject.SharedKernel项目参考 MyProject.SharedKernel

MyProject.Infrastructure (Class Library) MyProject.Infrastructure(类库)

  • Project Reference to MyProject.Core项目参考 MyProject.Core

MyProject.SharedKernel (Class Library) MyProject.SharedKernel(类库)

  • EnsureThat NuGet Package Reference确保 NuGet 包参考

MyProject.Function (Azure Function v3 Class Library) MyProject.Function(Azure Function v3 类库)

  • Project Reference to MyProject.Core项目参考 MyProject.Core
  • Project Reference to MyProject.SharedKernel项目参考 MyProject.SharedKernel
  • Project Reference to MyProject.Infrastructure对 MyProject.Infrastructure 的项目引用

MyProject.Web (ASP.NET Core 3.1) MyProject.Web (ASP.NET Core 3.1)

  • Project Reference to MyProject.Core项目参考 MyProject.Core
  • Project Reference to MyProject.SharedKernel项目参考 MyProject.SharedKernel
  • Project Reference to MyProject.Infrastructure对 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.MyProject.Web 中,我可以毫无问题地使用 EnsureThat 库,因为如果引用MyProject.SharedKernel ,后者又引用了 EnsureThat NuGet 包。 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 .出于某种原因,我不能做,即使它具有完全相同的参考MyProject.SharedKernelMyProject.Function项目相同。

Is there something about an azure function class library that prevents transitive references from working properly?是否存在阻止传递引用正常工作的 azure 函数类库? I would prefer not to have to also install the EnsureThat NuGet package in the MyProject.Function project directly.我不想还直接在MyProject.Function项目中安装确保 NuGet 包。

It seems that references in .net core using VS 2019 are a little flaky.使用 VS 2019 的 .net core 中的引用似乎有点不稳定。 While having this issue Microsoft released EF Core 3.1.1.在遇到此问题时,Microsoft 发布了 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.我决定使用 nuget 更新我引用 EF Core 3.1.1 的 EF Core 3.1.0 包。 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.在这一点上,我认为本地出了点问题,所以我将代码检查到 Azure Dev Ops 中,看看我们的门控构建是否会失败。 IT DID NOT!它没! At this point, I deleted all the code from my local machine and got the latest from Azure Dev Ops.此时,我从本地机器上删除了所有代码,并从 Azure Dev Ops 获取了最新代码。 When I tried building it complained of a missing file "project.assets.json" and told me to do a "dotnet restore".当我尝试构建它时抱怨缺少文件“project.assets.json”并告诉我进行“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!一旦它顺利完成,我的所有引用都被修复了,包括我的 azure 函数的传递引用问题!

Unfortunately, what you want is impossible.不幸的是,你想要的是不可能的。 This is no matter with VS 2019, the reason is this feature has not yet been implemented.这与 VS 2019 无关,原因是此功能尚未实现。

Azure Function can not reference Class Library now. Azure Function 现在无法引用类库。 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.但是你可以引用你的类库的dll文件,这意味着你可以在你的SharedKernel类库中输出并在你的azure函数中获得输出。

First, build the SharedKernel Class library, then reference to the dll of this.首先构建SharedKernel类库,然后引用this的dll。

在此处输入图片说明

在此处输入图片说明

In your azure function:在你的天蓝色函数中:

在此处输入图片说明

By the way, you can only use the output, using Ensure That package is still impossible.顺便说一句,你只能使用输出,使用Ensure That包仍然是不可能的。 You need to install it in your azure function.您需要将其安装在您的 azure 函数中。

Hope it helps.希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 .NET Core 3.1 类库和 .NET Core 3.1 Azure Function V3 类库之间的“Microsoft.Extensions.Options”版本冲突 - "Microsoft.Extensions.Options" version conflicts between .NET Core 3.1 Class Library and .NET Core 3.1 Azure Function V3 Class Library 引用 .net 核心类库到项目的问题 - Issue with reference .net core class library to project Azure功能与.net核心2类库 - Azure function with .net core 2 class library ASP.NET Core 3.1 API 参考 a.Net Standard class 库 - 在 Azure DevOps 中构建失败 - ASP.NET Core 3.1 API referring to a .Net Standard class library - build failed in Azure DevOps 在 .Net Core 3.1 类库中调用 iText7 PdfAcroForm.GetAcroForm() 时出现空引用异常 - Null Reference Exception when calling iText7 PdfAcroForm.GetAcroForm() in .Net Core 3.1 class library 从 .Net 标准类库引用 .Net Core 3.1 项目 - Referencing a .Net Core 3.1 project from a .Net Standard Class Library Azure App Servce 的 .Net Core 3.1 Web API 延迟问题 - .Net Core 3.1 Web API latency issue with Azure App Servce 引用ASP.NET Core类库 - Reference an ASP.NET Core Class Library 在 .NET 4.7.2 class 库中使用 EF Core 3.1 SQLite 数据库 - Using EF Core 3.1 SQLite database in .NET 4.7.2 class library 引用类库项目的ASP.NET Core Webapp Azure部署 - ASP.NET Core webapp Azure deployment with reference to class library project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM