编译C#库项目需要bindingRedirect [英] Compile C# library projects requiring bindingRedirect

查看:1052
本文介绍了编译C#库项目需要bindingRedirect的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我引用第三方DLL,需要bindingRedirect在app.config文件如下:

I am referencing a third party dll that requires a bindingRedirect in the app.config file as follows:

<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项目之间共享。 然而,我的图书馆找不到引用了。我得到以下警告:

I am trying to reference this in a C# library project. The library will be shared between a WCF project and MVC project. However the my library cannot find the references anymore. I get the following warning:

主要参考第三方无法得到解决,因为它   对框架组件的间接依赖System.Net.Http,   版本= 1.5.0.0,文化=中性公钥= b03f5f7f11d50a3a   这可能不是在当前的目标框架来解决。   .NETFramework,版本= V4.0。要解决此问题,请删除   参考第三方或重新定位你的应用程序框架   版本,其中包含System.Net.Http,版本= 1.5.0.0,   文化=中性公钥= b03f5f7f11d50a3a

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库。然而这种配置将被忽略。

I have added an app.config file to the library with the required bindingRedirect. However this configuration is ignored.

我也试过库转换为一个控制台应用程序。在这种情况下,它编译完美和工作。

I have also tried converting the library to a console application. In this case it compiles perfectly and works.

怎样才能编译库项目,需要assemblyBinding做bindingRedirect?

How does one compile a library project that requires assemblyBinding to do a bindingRedirect?

推荐答案

您得到一个编译时错误,因为第三方DLL从System.Net.Http暴露类型。你只需要添加引用System.Net.Http组件来解决这个问题。

You are getting a compile-time error because the third party DLL exposes types from System.Net.Http. You simply need to add the reference to the System.Net.Http assembly to resolve it.

使用的NuGet这样做。您希望微软HTTP客户端库包

Do so by using Nuget. You want the Microsoft HTTP Client Libraries package.

这篇关于编译C#库项目需要bindingRedirect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆