将 async/await 与 Microsoft.Bcl.Async 一起使用:找不到类型或命名空间名称 'async'

Use async/await with Microsoft.Bcl.Async: the type or namespace name 'async' could not be found

我需要在 .net framework 4、VS2013(Web 表单应用程序)上使用 async/await。我通过 nuget 安装了 Microsoft.Bcl.Async,但我总是得到:

The type or namespace name 'async' could not be found

如果我尝试定义一个名称空间,例如:

using Microsoft.Threading.Tasks;

我明白了

The type or namespace name 'Threading' does not exist in the namespace 'Microsoft'

那么我该如何使用 Microsoft.Bcl.Async?

您不能在 ASP.NET 上使用 Microsoft.Bcl.Async。即使你得到它来编译。它在运行时会有未定义的行为。

这是因为某些核心 ASP.NET 类型必须更改才能支持 async。 NuGet 包只包含编译器需要的类型;它不会修补 ASP.NET 运行时。