我正在尝试将项目重写为可移植类库。但问题是它使用的是 Async CTP,我无法将其编译为 WP 和 Windows Store App 的库。如果我不包含引用 AsyncCtpLibrary.dll,编译器会这样说
The type or namespace name 'Tasks' does not exist in the namespace 'System.Threading' (are you missing an assembly reference?)
如果我包含它,编译器仍然会说同样的错误并添加警告:
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".
我该如何忍受?
最佳答案
当前,当面向 .NET 4.5 和 Window Store 应用程序时,您只能在可移植应用程序中使用 async/await。在可移植之外,您可以使用适用于 .NET 4.0 和 Silverlight 5 的 Async Targeting Pack。
尽管如此,我们正在开发一个更新的异步目标包,它在面向 Phone 7.5、Silverlight 5 和 .NET 4.0 时增加了对可移植异步/等待的支持,请参阅:http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2691068-support-async-in-portable-class-libraries .您将在 10 月初看到。
更新:我们刚刚发布了测试版:http://blogs.msdn.com/b/bclteam/archive/2012/10/22/using-async-await-without-net-framework-4-5.aspx .
关于c# - 将异步 CTP 与可移植类库一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12597797/