gpt4 book ai didi

c# - 编译需要 bindingRedirect 的 C# 库项目

转载 作者:行者123 更新时间:2023-11-30 12:28:17 24 4
gpt4 key购买 nike

我在 app.config 文件中引用需要 bindingRedirect 的第三方 dll,如下所示:

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.10.0" newVersion="2.1.10.0" />
</dependentAssembly>
...
</assemblyBinding>
</runtime>

我试图在 C# 库项目中引用它。该库将在 WCF 项目和 MVC 项目之间共享。但是我的图书馆再也找不到这些引用资料了。我收到以下警告:

The primary reference "ThirdParty" could not be resolved because it has an indirect dependency on the framework assembly "System.Net.Http, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "ThirdParty" or retarget your application to a framework version which contains "System.Net.Http, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

我已将一个 app.config 文件添加到库中,其中包含所需的 bindingRedirect。但是,此配置将被忽略。

我还尝试过将库转换为控制台应用程序。在这种情况下,它可以完美编译并运行。

如何编译一个需要 assemblyBinding 来执行 bindingRedirect 的库项目?

最佳答案

您收到编译时错误,因为第三方 DLL 公开了 System.Net.Http 的类型。您只需添加对 System.Net.Http 程序集的引用即可解决它。

使用 Nuget 执行此操作。你想要 Microsoft HTTP Client Libraries package .

关于c# - 编译需要 bindingRedirect 的 C# 库项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22404015/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com