开发者

Can I add .NET 3.5+ NuGet packages to a Mono for Android project?

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...


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜