How to use the Microsoft.Bcl.Async right? How to use the Microsoft.Bcl.Async right? wpf wpf

How to use the Microsoft.Bcl.Async right?


Summary:

There's a couple of workarounds available to you:

  1. Install the Microsoft.Bcl.Async package to the referencing project.

  2. 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.

  3. 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.

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.

Long story:

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.

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.


Use Async Targeting Pack for Visual Studio 11 instead.

Install-Package Microsoft.CompilerServices.AsyncTargetingPack

If you prefer to use the Microsoft.Bcl.Async prerelease, you'll have to add it to all the projects. Next release of Bcl.Async should have improved messaging to better detail that.

If you're using VS 2010, the only thing that I know of that gives you async/wait is the AsyncCTP; so, it doesn't make sense to use Microsoft.Bcl.Async in VS 2010.

update:

W.R.T to Microsoft.Bcl.Async: The issue around the MSB warning ("cannot be resolved...indirect dependency..." is known and being addressed. In some future update (to MSBuild and Microsoft.Bcl.Async) this will be fixed and you won't have to include Microsoft.Bcl.Async in both projects.