我可以添加 .NET 3.5+ NuGet 包到 Mono for Android 项目?
Mono for Android 可以从 Mono 框架访问 .NET 4.0 的大部分内容。不幸的是,当我尝试在 Visual Studio 中添加专门针对 .NET 3.5 或更高版本且具有 /lib/net*/ 文件夹结构的 NuGet 包时,它会抛出错误。
您正在尝试将此软件包安装到目标项目中 'MonoAndroid,Version=v2.1',但包中不包含任何 与该框架兼容的程序集引用。
如果 NuGet 包没有 .NET 版本细分,或者您删除了该子目录结构并将其发布到 NuGet 源,则它可以正常工作。例如,NUnit 只有一个 /lib/ 文件夹,没有按 .NET 框架版本进一步细分,并且安装良好。
NuGet 似乎可以使用
项目文件 XML 元素来检查兼容性。如果是这样,那就是问题所在,因为 Android 的 Mono 篡夺了该元素以表示“目标 Android 框架版本”。例如,要以 Android v2.2 为目标,它看起来像这样:
<TargetFrameworkVersion>v2.1</TargetFrameworkVersion>
在项目属性对话框中,“[.NET] Target Framework”下拉列表将是“Minimum Android to target”的下拉列表,它会影响这个 XML 元素。
如果这是 NuGet 遇到的问题,我将无法将未修改的 NuGet 用于版本特定的包,直到将 Android 应用程序定位为至少 冰淇淋三明治 (v4.0)。
旁注
您可以通过项目引用引用这些包中的 DLL。它肯定会向您发出警告,但您可以相当安全地忽略它(假设程序集不会偏离 Mono 中实现的代码太远)。
“Some.dll”或其依赖项之一需要更高版本的 .NET Framework 比项目中指定的框架...
Mono for Android has access to most of .NET 4.0 from the Mono framework. Unfortunately, when I try to add NuGet packages in Visual Studio that specifically target .NET 3.5 or beyond, with a /lib/net*/ folder structure, it tosses up an error.
You are trying to install this package into a project that targets
'MonoAndroid,Version=v2.1', but the package does not contain any
assembly references that are compatible with that framework.
If a NuGet package doesn't have the .NET version breakdown, or one where you removed that subdirectory structure and published it to a NuGet source, it works fine. For example, NUnit just has a /lib/ folder with no further breakdown by .NET framework version and installed fine.
It appears NuGet could be checking compatibility by using the <TargetFrameworkVersion>
project file XML element. If so, that is the problem as Mono for Android usurps that element to mean a "target Android framework version". For example, to target Android v2.2, it looks like this:
<TargetFrameworkVersion>v2.1</TargetFrameworkVersion>
In the project properties dialog, where the "[.NET] Target framework" drop-down would be is a drop-down for "Minimum Android to target" that affects this XML element.
If this is the problem NuGet is encountering, I won't be able to use unmodified NuGet for version-specific packages until targeting an Android app for a minimum of Ice Cream Sandwich (v4.0).
Side note
You can reference the DLLs from these packages via project reference. It definitely throws a warning at you, but you can ignore it fairly safely (assuming the assembly doesn't wander too far from the code implemented in Mono).
'Some.dll', or one of its dependencies, requires a later version of
the .NET Framework than the one specified in the project...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不可以,程序集必须根据 2.0.5 配置文件进行编译才能被 Mono for Android 使用。您可以通过使用 Mono for Android 类库模板或使用为 Silverlight 编译的程序集来实现此目的。
Android 版本(2.2、3.0、4.0)与编译程序集所针对的 .NET BCL 版本无关。
No, assemblies must be compiled against the 2.0.5 profile in order to be used by Mono for Android. You can achieve this by using the Mono for Android Class Library template or by using assemblies compiled for Silverlight.
The Android version (2.2, 3.0, 4.0) is not related to the version of the .NET BCL an assembly is compiled against.