简体   繁体   English

多目标.NET程序集在.NET 4.5和.NET 4上使用async / await

[英]Multi-targeting .NET assembly to use async/await on .NET 4.5 and .NET 4

I am currently trying to build a small portable library for which I need to use async/await. 我目前正在尝试构建一个小型便携式库,我需要使用async / await。 My goal is that I want to be able to use my library on both the .NET 4, as well as the .NET 4.5 runtime. 我的目标是希望能够在.NET 4以及.NET 4.5运行时使用我的库。 Ideally I would like to use the Microsoft.Bcl.Async pack when targeting .NET 4, whereas for .NET 4.5 I want to use the built-in async/await support without including the Bcl pack. 理想情况下,我想在面向.NET 4时使用Microsoft.Bcl.Async包,而对于.NET 4.5,我想使用内置的async / await支持而不包括Bcl包。

That said, I would like to have the bcl.async dll excluded from my project when compiling to .NET 4.5, as this gives me warnings about ambigous references between the built-in async of C# 5 in .NET 4.5 and the bcl.async pack. 也就是说,我想在编译到.NET 4.5时将bcl.async dll从我的项目中排除,因为这给了我关于.NET 4.5中C#5的内置异步与bcl.async之间的不明引用的警告包。

Is this possible, if so how, else what would be a better way of going about this problem? 这是可能的,如果是这样,那么什么是更好的解决这个问题的方法?

I ended up using the answer from @StephenCleary, whereas I targeted my PCL to .NET 4.0, and used the Bcl.Async pack. 我最终使用了来自@StephenCleary的答案,而我将我的PCL定位到.NET 4.0,并使用了Bcl.Async包。

Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM