如何使用Microsoft.Bcl.Async吧? [英] How to use the Microsoft.Bcl.Async right?

查看:1864
本文介绍了如何使用Microsoft.Bcl.Async吧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 Microsoft.Bcl.Async 在一个项目中,该项目是一个由其他项目不使用异步功能引用。

I use the Microsoft.Bcl.Async package in a project and this project is a referenced by another project that does not use async features.

现在,当我编译溶液(或仅第二个项目),我得到这个错误警告:

Now I get this error warning when I compile the solution (or only the second project):

主要参考XYZ.dll无法得到解决,因为它的框架组件的间接依赖System.Runtime,版本= 1.5.11.0,文化=中性公钥= b03f5f7f11d50a3a,这可能不是解决当前目标框架。 .NETFramework,版本= V4.0。要解决此问题,要么删除参考XYZ.dll或重新定位你的应用程序,其中包含一个框架版System.Runtime,版本= 1.5.11.0,文化=中性公钥= b03f5f7f11d50a3a。

The primary reference "XYZ.dll" could not be resolved because it has an indirect dependency on the framework assembly "System.Runtime, Version=1.5.11.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 "XYZ.dll" or retarget your application to a framework version which contains "System.Runtime, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".

我在这两个项目中使用的app.config:

I use in both projects this app.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:bcl="urn:schemas-microsoft-com:bcl">
      <dependentAssembly bcl:name="System.Runtime">
        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.5.16.0" newVersion="2.5.16.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.5.16.0" newVersion="2.5.16.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

我在做什么错了?

What I'm doing wrong?

我不想引用异步包的DLL。

I don't want to reference the async package dlls.

我不能使用.NET 4.5的目标。必须.NET 4。

I can't use .Net 4.5 target. It must be .Net 4.

目标框架的所有项目:.NET Framework 4的

Target Framework for all projects: .NET Framework 4

推荐答案

摘要

有可用一对夫妇的解决方法给你:

There's a couple of workarounds available to you:


  1. 安装的 Microsoft.Bcl.Async 的包引用的项目。

安装的 Microsoft.Bcl.Build 的包引用的项目。这包含实际的修复和完全是一个构建时的依赖性。当你这样做,你必须在项目App.Config中相应的绑定重定向(如你上面列出的) - 不论它是一个类库,Web项目或可执行

Install the Microsoft.Bcl.Build package to the referencing project. This contains the actual fix, and is solely a build-time dependency. When you do this, you must have the appropriate binding redirects in the project's App.Config (such as what you've listed above) - regardless of whether it is a class library, web project or an executable.

如果您不想在任何包的相关性,Microsoft.Bcl.targets文件(Microsoft.Bcl.Build安装)内抢PropertyGroup元素中的内容,并在该底部插入最后一个导入元素之后引用的项目。

If you don't want a dependency on any package, grab the contents of the PropertyGroup element within Microsoft.Bcl.targets file (installed with Microsoft.Bcl.Build), and insert it at the bottom of the referencing project after the last Import element.

注意:而且,任何选项,你选择上面,当你把该呈现Microsoft.Bcl.Async的依赖(与老Microsoft.CompilerServices.AsyncTargetingPack)库,就必须把那些二进制文件(System.Runtime,System.Threading.Tasks,Microsoft.Threading.Tasks。*)与应用程序/包,使用你的库。

Note: Which ever option you choose above, when you ship a library that takes a dependency on Microsoft.Bcl.Async (as with the old Microsoft.CompilerServices.AsyncTargetingPack), you must ship those binaries (System.Runtime, System.Threading.Tasks, Microsoft.Threading.Tasks.*) with the application/package that uses your library.

长的故事

正如彼得指出,这是一个已知的问题,只发生Microsoft.Bcl.Async而不是Microsoft.CompilerServices.AsyncTargetingPack,由于他们的设计方式。

As Peter pointed out this is a known issue that only occurs for Microsoft.Bcl.Async and not Microsoft.CompilerServices.AsyncTargetingPack, due to the way they are designed.

Microsoft.Bcl.Async设计的一部分是反向移植(通过的NuGet包)一些新的.NET 4.5组件(System.Runtime,System.Threading.Tasks),这样他们将在4.0上运行。的MSBuild不喜欢这一点,并使其相信引用库已在组装的依赖,从一个新的框架版本。在Microsoft.Bcl.Build封装的解决方法修复此。

Part of the design of Microsoft.Bcl.Async was to backport (via a NuGet package) some new .NET 4.5 assemblies (System.Runtime, System.Threading.Tasks) so that they would run on 4.0. MSBuild does not like this, and it causes it to believe that the referencing library has taken a dependency on an assembly from a newer framework version. The workaround in Microsoft.Bcl.Build package fixes this.

这篇关于如何使用Microsoft.Bcl.Async吧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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