编译C#库项目需要bindingRedirect项目、bindingRedirect

由网友(塵世孤行)分享简介:我引用第三方DLL,需要bindingRedirect在app.config文件如下:I am referencing a third party dll that requires a bindingRedirect in the app.config file as follows:我引用第三方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.

阅读全文

相关推荐

最新文章