Xamarin Mono 项目中的 Microsoft.Threading.Tasks.Extensions [英] Microsoft.Threading.Tasks.Extensions in Xamarin Mono projects

查看:26
本文介绍了Xamarin Mono 项目中的 Microsoft.Threading.Tasks.Extensions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为 Simple.OData.Client 构建了一个 NuGet 包,支持 Xamarin Android 和 iOS.该库使用 Microsoft.Bcl.Async.使用 Android 和 iOS 模拟器的测试正常,但是当我将这个新的 NuGet 包安装到另一个项目中时,它无法编译 Droid/Touch 项目并显示以下消息:

I have built a NuGet package for my Simple.OData.Client with support for Xamarin Android and iOS. This library uses Microsoft.Bcl.Async. Tests using Android and iOS simulator went OK, but when I install this new NuGet package into another project, it fails to compile Droid/Touch projects with the following message:

C:Program Files (x86)MSBuildXamarinAndroidXamarin.Android.Common.targets(720,2): error : Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'Microsoft.Threading.Tasks.Extensions, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Perhaps it doesn't exist in the Mono for Android profile?
C:Program Files (x86)MSBuildXamarinAndroidXamarin.Android.Common.targets(720,2): error : File name: 'Microsoft.Threading.Tasks.Extensions.dll'

当然,Mono 平台还没有 Microsoft.Bcl.Async 包,另一方面,由于库测试在这些平台上通过,我想这更像是一个挑战,让 Visual Studio 开心而不是做一些代码修改.

Of course there is no Microsoft.Bcl.Async pack (yet) for Mono platforms, on the other hand since the library tests pass on these platforms, I guess this more of a challenge to make Visual Studio happy rather than do some code modification.

有没有人设法在依赖 Microsoft.Bcl.Async 的 Mono PCL 上使用?

Has anyone managed to use on Mono PCLs dependent on Microsoft.Bcl.Async?

推荐答案

一般来说,如果你的包中的代码依赖于另一个 NuGet 包,你需要声明一个包依赖,这样任何安装你的包的人都会得到你所依赖的也上.这应该解决这样的问题.

Generally, if the code in your package depends on another NuGet package, you need to declare a package dependency so that anyone installing your package will get the one you depend on too. That should take care of issues like this.

然而,在这种情况下,情况要复杂得多.由于 Microsoft.Bcl.Async 不支持 Mono 平台,因此您不能声明该包依赖项(或者如果您这样做了,它总是无法安装).不幸的是,Microsoft.Bcl.Async 的许可证将其限制为Windows 平台".我不是律师,但我认为这意味着您不应将 Microsoft.Threading.Tasks.Extensions.dll 作为软件包的一部分分发.最后,目前还没有对 Mono 平台的官方 PCL 支持,所以如果你想出一个现在有效的解决方案,当官方 PCL 支持出来时,它可能会改变.

However, in this case it is a lot more complicated. Since Microsoft.Bcl.Async doesn't support Mono platforms, you can't declare that package dependency (or if you did it would always fail to install). Unfortunately the license for Microsoft.Bcl.Async restricts it to "Windows platforms". I'm not a lawyer but I think that means you shouldn't distribute Microsoft.Threading.Tasks.Extensions.dll as part of your package. Finally, there's no official PCL support for Mono platforms yet, so if you do come up with a solution that works now it may change when official PCL support comes out.

如果您想尝试使其工作,您基本上需要做的是创建您自己的 DLL,其名称与 Microsoft.Bcl 和 Microsoft.Bcl.Async 中的名称相同,以便在 Mono 平台上使用.在这些程序集中,为 Mono 已经实现的类型(可能应该是 System.* DLL 中的类型)放置类型,并为其他类型创建您自己的实现(AsyncBridge 源代码对此很有用).这就是我为我的 BUILD 2012 PCL 演示之一所做的.其代码在此处.AsyncFacades 和 AsyncBridge 是相关项目.

If you want to attempt getting this to work, what you basically need to do is create your own DLLs with the same names as are in Microsoft.Bcl and Microsoft.Bcl.Async for use on Mono platforms. In those assemblies, put type forwards for the types that Mono already implements (which should probably be the types in the System.* DLLs), and create an implementation of your own for the other ones (the AsyncBridge source code is useful for this). This is what I did for one of my BUILD 2012 PCL demos. The code for that is here. AsyncFacades and AsyncBridge are the relevant projects.

这篇关于Xamarin Mono 项目中的 Microsoft.Threading.Tasks.Extensions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆