我试图将项目重写为可移植类库.但问题是它使用的是Async CTP,我无法将其编译为WP和
Windows Store App的库.如果我不包含引用AsyncCtpLibrary.dll,编译器会说
@H_404_2@
The type or namespace name ‘Tasks’ does not exist in the namespace ‘System.Threading’ (are you missing an assembly reference?)
@H_404_2@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,PublicKeyToken=b77a5c561934e089”.
我该怎么忍受?
解决方法
简单回答 – AsyncCTP在Visual Studio 2012中不起作用,不能在任何项目中使用.对于.NET 4.0和Silverlight 5,您可以从NuGet安装以类似方式工作的Async Targeting Pack. 只有在针对WinRT,.NET4.5或Windows Phone 8时才支持异步/等待在可移植类库中,即使这样,使用也非常有限.我不能在这里详细介绍,因为Windows Phone 8 SDK仍然在NDA下. 对于WP7.5和VS2012,目前无法使用async / await,但此平台的更新Async Targeting Pack应该可以使用. 另请注意,AsyncCTP和Async Targeting Pack不能在便携式类库中使用,并且它不太可能在将来发生变化.结果是在VS2010中,您不能在Portable Class Libraries中使用async / await.