简体   繁体   English

.NET 4.0中的异步/等待:兼容的DLL集?

[英]async/await in .NET 4.0: a Compatibe Set of DLLs?

I would like to use async / await syntax when targeting .NET FX 4.0. 在定位.NET FX 4.0时,我想使用async / await语法。

I fetched the Microsoft.Bcl.Async.1.0.168 Nuget package. 我获取了Microsoft.Bcl.Async.1.0.168 Nuget程序包。
It has the assembly Microsoft.Threading.Tasks, Version=1.0.12.0 它具有程序集Microsoft.Threading.Tasks, Version=1.0.12.0
which implements all the magic and has a reference to System.Runtime, Version=1.5.11.0 . 它实现了所有魔力,并引用了System.Runtime, Version=1.5.11.0

The System.Runtime assembly is available in the companion Nuget package Microsoft.Bcl.1.1.8 , but has a different version 2.6.8.0 in there. 随附的Nuget软件包Microsoft.Bcl.1.1.8提供了System.Runtime程序集,但其中具有其他版本2.6.8.0

As a result, its usages won't compile without special tricks and hacks. 结果,如果没有特殊的技巧和hack,它的用法将无法编译。
The DLL reference does not resolve because of the version number mismatch. 由于版本号不匹配,无法解析DLL参考。

So, is it possible to get a consistent set of BCL Async DLLs which reference one another by matching version numbers and which can be compiled right away? 因此,是否有可能获得一组一致的BCL异步 DLL,它们通过匹配版本号相互引用,并且可以立即进行编译?

(Tried looking in other Nuget versions or other target ilb folders, found some matching versions but they're for a different platform and with a different set of classes, eg with a duplicate Task class) (尝试在其他Nuget版本或其他目标ilb文件夹中查找,找到了一些匹配的版本,但它们适用于不同的平台和不同的类集,例如具有重复的Task类)

UPD: Also mind the runtime behavior: with netfx45, these assemblies get unified into runtime and work like a charm, but on a vanilla netfx40 system you'd get a System.IO.FileLoadException with Could not load file or assembly 'System.Threading.Tasks, Version=1.5.11.0, […] UPD:还请注意运行时的行为:使用netfx45,这些程序集可以统一到运行时并像超级按钮一样工作,但是在普通的netfx40系统上,您将获得System.IO.FileLoadExceptionCould not load file or assembly 'System.Threading.Tasks, Version=1.5.11.0, […]

All you need is the one Nuget package, and VS2012 or higher. 您所需要的只是一个Nuget软件包,以及VS2012或更高版本。 (with Nuget 2.3 or higher) (使用Nuget 2.3或更高版本)
https://www.nuget.org/packages/Microsoft.Bcl.Async https://www.nuget.org/packages/Microsoft.Bcl.Async

Nuget will install all dependencies with the correct version (unless you specify otherwise). Nuget将使用正确的版本安装所有依赖项(除非您另外指定)。 I've done this many times, and I'll tell you right now you only need to use that one package, and if its not working there is something else wrong with your setup. 我已经做过很多次了,现在我将告诉您,您只需要使用一个软件包,如果无法使用,则您的设置还有其他问题。

If you don't have VS2012, you can download the Express (free) version in order to use this. 如果您没有VS2012,则可以下载Express(免费)版本以使用此版本。

If my word isnt enough, you can read the official MSDN blog on the subject. 如果我的话还不够,您可以阅读有关该主题的MSDN官方博客。
http://blogs.msdn.com/b/bclteam/archive/2012/10/22/using-async-await-without-net-framework-4-5.aspx http://blogs.msdn.com/b/bclteam/archive/2012/10/22/using-async-await-without-net-framework-4-5.aspx
http://blogs.msdn.com/b/bclteam/archive/2013/04/17/microsoft-bcl-async-is-now-stable.aspx http://blogs.msdn.com/b/bclteam/archive/2013/04/17/microsoft-bcl-async-is-now-stable.aspx

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM