问题
I have been using .NET 4.5 in Xamarin Studio with portable libraries and a Xamarin.Mac project. When the Xamarin.Mac project is set to .NET 4.5 and Microsoft Async is added via nuget, compile in Debug will succeed but Release/AppStore will fail with
error MM2002: Failed to resolve assembly: 'System.Threading.Tasks,
In this case, it is unnecessary to add the dlls (System.Threading.Tasks and System.Runtime) from BCL because they are already in .NET 4.5. If you switch to .NET 4.0 it will work, but I have a lot of code already in .NET 4.5 that cannot be reversed because of other dependencies.
Somehow, BCL is not recognizing the Xamarin.Mac .NET 4.5 project as .NET 4.5 and still requiring the dlls.
To replicate:
- Create a new Xamarin.Mac project
- Set it to .NET 4.5
- Use nuget to fetch Microsoft Async (notice correctly it does not pull in System.Threading.Tasks or System.Runtime)
- Switch to Release
- Compile
How does BCL know if .NET 4.0 or .NET 4.5 is used? Maybe there is something I can declare in the csproj to make it recognize that System.Threading.Tasks (and System.Runtime) is already included. Or maybe some Environment variable? Or...?
Note. It is possible to reference the System.Threading.Tasks ans System.Runtime from the net40 nuget folder. And in the test project, this actually works - though it complains about "The predefined type System.Runtime.CompilerServices.AsyncStateMachineAttribute' is defined multiple times. Using definition from
mscorlib.dll'" However, in my case I have a portable library which uses EventArgs and the build fails with error CS1684: Reference to type System.EventArgs' claims it is defined assembly
System.Runtime - which of course it isn't.
回答1:
I'm not sure how well Xamarin.Mac supports PCLs. You can try to add an app.config with binding redirects, similar to what is described here: http://motzcod.es/post/78863496592/portable-class-libraries-httpclient-so-happy
Otherwise, I'd suggest filing a bug with Xamarin.
来源:https://stackoverflow.com/questions/22361526/xamarin-mac-4-5-with-bcl-async-release-compile-fails-to-resolve-system-threading