Thursday, April 26, 2012

No more of that sinking feeling when using async for .Net 4/Silverlight 5 Projects - The Async Targeting Pack for Visual Studio 11 now available (Nuget: "Microsoft.CompilerServices.AsyncTargetingPack")

C# Frequently Asked Questions - Async Targeting Pack for Visual Studio 11 now available for .NET 4 and Silverlight 5

"If you’ve held off on trying Visual Studio 11 Beta because your .NET 4 or Silverlight 5 app uses the Async CTP, your wait is over! Today we’ve published the Async Targeting Pack for Visual Studio 11, a NuGet package that lets your Visual Studio 11 projects target .NET 4 and Silverlight 5 while taking advantage of C#’s new await keyword. While Visual Studio 11 provides built-in support for await in projects that target .NET 4.5 or .NET for Metro style apps, this targeting pack provides the API support to expand the set of target platforms to include .NET 4 and Silverlight 5 as well.


Microsoft Downloads - Async Targeting Pack for Visual Studio 11

Async Targeting Pack for Visual Studio 11: End-User License Agreement, Installation and Release Notes

Version: 1.0.0
Date published: 4/26/2012


AsyncTargetingPack-EULA.html, 9 KB
AsyncTargetingPack-InstallationAndReleaseNotes.html, 13 KB

The "Async Targeting Pack for Visual Studio 11" enables projects targeting .NET Framework 4.0 or Silverlight 5 to use the Async language feature in C# 5 and Visual Basic 11. This pack requires Visual Studio 11 and will not work with Visual Studio 2010.

The pack contains the API support necessary to use the 'async' and 'await' keywords in C# 5.0 and Visual Basic 11, as well as a set of Task-based adapter APIs that allow using some of the existing asynchronous APIs with the new language keywords.

This targeting pack is not required for projects targeting .NET Framework 4.5 or .NET for Metro style apps. It is only required for projects targeting Silverlight 5 and .NET Framework 4.0. Earlier platform releases are not supported.


If you are already familiar with NuGet:
The package ID of the Async Targeting Pack that you can use when searching for it is: "Microsoft.CompilerServices.AsyncTargetingPack".

If you are not yet very familiar with NuGet:
Download the "AsyncTargetingPack-InstallationAndReleaseNotes.html" document from this page and follow the links in that document to learn how to use NuGet with Microsoft Visual Studio.


So kind of a mix of both worlds. If you want to target .Net 4.0, yet want to use async, this is your ticket.


Related Past Post XRef:
Visual Studio Async CTP (Version 3) Released - Lots of compatibility added, bugs squashed, features added and the EULA updated to allow Production usage (not encouraged, but it IS allowed now)
PDC10 Async Round-up

1 comment:

AGlez said...

Hi Greg

I have one concern with the new targeting pack and developing in VS 11 while targeting .NET 4.

In our office we created an small spike WCF solution (Server/Client) that uses a ServiceContract let's say ISomeService that has one operation contract that returns a Task. For creating this we used VS 11 with the new targeting pack and of course we were targeting .NET 4 for both projects Server and Client.

Now the problem is that even though we know WCF 4 cannot serialize Tasks our solution compiled and ran perfectly in our development PC but when testing it in an XP PC with just .NET 4 installed for obvious reasons (.NET 4.5 doesn't support XP) our bits failed with the exception that Tasks cannot be serialized etc etc. perfectly understandable since .NET 4 cannot serialize Tasks.

Now we can avoid this and not use Task returning services in WCF since we are targeting .NET 4 because we now about this problem and NOT because when we were developing and testing VS 11 even targeting .NET 4 failed, which is the behavior I will expect from VS 11 to fail when I try to run a project that targets .NET 4 the way is not supposed to be used.

So my real concern is what kind of other problems we can be incurring in using async/await features while developing in VS 11 + Async Targeting pack even though you target .NET 4 rather than using VS 2010 + Async CTP. I mean we will be incurring into those problems since we will be developing in VS 11 thinking that we are safe because we targeted .NET 4 framework when in reality when we test our apps in an environment with just .NET 4 they can fail.

Even worse my wild guess is that all these problems are related to the fact that .NET 4.5 is an in-place update to .NET 4 so what ever .NET 4.5 fixed, improved, added or replaced from .NET 4 will be the real stuff we will be using in our development environments with VS 11 and .NET 4.5 no matters we explicitly target .NET 4 leading to a possible failure when our apps run in a just .NET 4 environment.

So my point here is what is the advantage to use VS 11 + Async targeting pack for targeting .NET 4 over VS 2010 + Async CTP if at the end chosing the first can shoot ourselves in the foot.

I would really appreciate if someone knows a way to overcome this problem (I mean being able to properly use VS 11 + Async targeting pack while targeting .NET 4 knowing that our apps will safely run in for example XP), probably we did something wrong with our spike WCF solution. Any feedback will be greatly appreciated.

by the way does anyone know if at the end .NET 4.5 will support XP this will make our lives easier ;-) or if at least the final .NET 4.5 will be a side by side installation rather than in-place update (I guess this could solve my problem as well eventhough I much prefer .NET 4.5 supporting XP so we can all make use of the new features at full capacity)