3
votes

I am currently trying to build a small portable library for which I need to use 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. 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.

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.

Is this possible, if so how, else what would be a better way of going about this problem?

1
Do you wish to compile the library under .net 4.0 or .net 4.5 ? how do you determine what function to run ?ilansch
Are you saying that if you have a PCL that references Bcl.Async and a .Net 4.5 application that references that library, you're getting the warnings?svick
@ilansch: I wish to compile my library to both .net 4.0 as well as 4.5. What I basically want is to make sure that my .net 4.0 version includes and references the bcl.async library, whereas the .net 4.5 version should not, since the functionality is already included in the framework.Søren Engel
@svick: No, rather that I've tried to set my pcl to compile to .net 4.0, whilst referencing the bcl.async library, but when I compile to .net 4.5, the compiler complains about having both the async coming from the bcl.async library as well as the one from the framework itself.Søren Engel
@SørenEngel: That's normal, and is an unfortunate side effect of how NuGet interacts with PCLs. If you change your PCL targets, you should uninstall all NuGet packages first, change the targets, and then re-install them. I recommend you just target .NET 4.0 with Microsoft.Bcl.Async.Stephen Cleary

1 Answers

4
votes

I ended up using the answer from @StephenCleary, whereas I targeted my PCL to .NET 4.0, and used the Bcl.Async pack.

Thanks!