Using Async CTP with Portable Class Library
Asked Answered
D

3

6

I am trying to rewrite a project into a Portable Class Library. But the problem is that it is using Async CTP, and I can't compile it as a library for WP and Windows Store App. If I don't include reference AsyncCtpLibrary.dll, compiler says that

The type or namespace name 'Tasks' does not exist in the namespace 'System.Threading' (are you missing an assembly reference?)

If i include it, compiler still says the same errors and adds a warning:

The primary reference "AsyncCtpLibrary" could not be resolved because it has an indirect dependency on the framework assembly "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETPortable,Version=v4.0,Profile=Profile104". To resolve this problem, either remove the reference "AsyncCtpLibrary" or retarget your application to a framework version which contains "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".

How should I bear with that?

Duty answered 26/9, 2012 at 8:42 Comment(0)
A
3

Simple answer - AsyncCTP is not working in Visual Studio 2012 and cannot be used in any project. For .NET 4.0 and Silverlight 5 you can install Async Targeting Pack from NuGet that works in a similar fashion.
Async/await is in Portable Class Library supported only when targeting WinRT, .NET4.5 or Windows Phone 8 and even then the use is pretty limited. I can't go into more details here, because the Windows Phone 8 SDK is still under NDA.
For WP7.5 and VS2012 there is currently no way how to use async/await, but updated Async Targeting Pack for this platform should be available sometime.
Note also that AsyncCTP and Async Targeting Pack can't be used in Portable Class Libraries and it's unlikely it will change in the future. The result is in VS2010 you cannot use async/await in Portable Class Libraries.

Amylose answered 26/9, 2012 at 11:23 Comment(3)
So, I should keep two different class versions for each project?Duty
I have been solving this issue in VS2010 - I ended up with one Project folder for my application logic with two csproj files, one for WinRT and second for WP7.5. I am then referencing the same files in both projects and I also use conditional build variables like #if etc. It worked pretty fine with some limitations.Amylose
You're also under nda not to even mention that you might be involved in the wp8sdk - first rule of fight club! :)Moriahmoriarty
D
5

You can only currently use async/await in portable when targeting .NET 4.5 and Window Store apps. Outside of portable, you can use the Async Targeting Pack for .NET 4.0 and Silverlight 5.

In saying that though, we are working on an updated async targeting pack that adds support for async/await in portable when targeting Phone 7.5, Silverlight 5 and .NET 4.0, see: http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2691068-support-async-in-portable-class-libraries. You will see this early October.

Update: We just release a beta of this: http://blogs.msdn.com/b/bclteam/archive/2012/10/22/using-async-await-without-net-framework-4-5.aspx.

Detection answered 26/9, 2012 at 14:43 Comment(0)
A
3

Simple answer - AsyncCTP is not working in Visual Studio 2012 and cannot be used in any project. For .NET 4.0 and Silverlight 5 you can install Async Targeting Pack from NuGet that works in a similar fashion.
Async/await is in Portable Class Library supported only when targeting WinRT, .NET4.5 or Windows Phone 8 and even then the use is pretty limited. I can't go into more details here, because the Windows Phone 8 SDK is still under NDA.
For WP7.5 and VS2012 there is currently no way how to use async/await, but updated Async Targeting Pack for this platform should be available sometime.
Note also that AsyncCTP and Async Targeting Pack can't be used in Portable Class Libraries and it's unlikely it will change in the future. The result is in VS2010 you cannot use async/await in Portable Class Libraries.

Amylose answered 26/9, 2012 at 11:23 Comment(3)
So, I should keep two different class versions for each project?Duty
I have been solving this issue in VS2010 - I ended up with one Project folder for my application logic with two csproj files, one for WinRT and second for WP7.5. I am then referencing the same files in both projects and I also use conditional build variables like #if etc. It worked pretty fine with some limitations.Amylose
You're also under nda not to even mention that you might be involved in the wp8sdk - first rule of fight club! :)Moriahmoriarty
F
1

You can try to use the AsyncBridge project instead of the AsyncCTP. I don't know if it will help. You'll have to compile in VS2012 to get this to work though (you can still target .NET4.0):

Foxed answered 26/9, 2012 at 8:45 Comment(2)
Is there any other way to do it? Because I am developing for wp under Windows 7 with vs2010.Duty
you could try to compile the project that need async support in VS2012, and then reference those dll's in your VS210 projectFoxed

© 2022 - 2024 — McMap. All rights reserved.