What version of .NET is Xamarin.Mac Full? What version should my libraries reference?

TonyValentiTonyValenti USMember ✭✭

Hi All,
I have a cross-platform app that I'm working on. What version of .NET should I set my projects to use so that they essentially use the same version on Mac and PC? (Or maybe there's another way to handle this?)

Right now my main mac project is using "Xamarin.Mac Full" but it seems as though it doesn't like .NET 4.5.1 references.

Answers

  • TonyValentiTonyValenti USMember ✭✭

    I think a related question has to do with .NET Core. When I'm building my cross-platform libraries, should I choose a .NET version or .NET core 2.0?

    I feel like I'm in "Version Hell". :-)

  • ChrisHamonsChrisHamons USXamarin Team Xamurai

    tl;dr;

    A netstandard2 library should work file assuming your are using the latest builds and is preferred. If you are using Xamarin.Mac Full profile, you'll need to add

    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>

    to your project with a text editor, but it should just work.

    If that doesn't work, you'll need to have a matching library for the Xamarin.Mac Target Framework flavor you are using. Modern is like iOS and you'll need to compile specially against it. Full can consume any .NET library assuming you hack the TargetFrameworkVersion in your project to be high enough.

    Long Version

    It is unfortunate that this is as complicated as it currently is, but it is a function of what's going on "under the hood". One huge difference between Xamarin.Mac Modern, Full, Xamarin.iOS, and the "desktop" mono is what Base Class Library (BCL) API they surface. The BCL covers things like System.Linq, System.Reflection, and such.

    The different products surface a different subset of the whole:

    • "Desktop" mono, or .net console applications pretty much give you everything (ls -la /Library/Frameworks/Mono.framework/Versions/Current/lib/mono/). There are a few difference based on what TargetFramework you choose, but it's all there.
    • This does not work at all with iOS (or XM Modern, which is related). That surface is both huge (footprint wise) and contains things like System.Configuration which uses reflection in linker unsafe ways. So those platforms drastically trim the BCL subset to something appropriate for tha tuse case.
    • Xamarin.Mac Full is "almost" desktop mono. We trim a few things, such as System.Drawing which for various historical reasons cause immense pain to customers, but if you squint hard enough you can't tell the difference for almost all users.
      • Full is actually close enough that it "lies" to nuget and can consume a huge percentage of nugets that ship "net45" and such.
      • Because we're consuming the "latest" assemblies from mono when we build, Full has the entire 4.7 surface pretty much.
      • The only downside of Full is that today we set the TargetFrameworkVersion as 4.5 and not 4.6.1 or 4.7. We are going to expose this in the UI at one point, and I've been pondering if there is a safe way to just "auto-bump" users to 4.7 in a future release. Today though, you have to add the tag to your project manually to consume certain nugets or netstandard2 libraries.

    The future and great hope in the distance is netstandard2. It unifies enough of this subset to let you compile your library one time (using the common subset) and consume it in all of these scenarios.

    The feature is hot off the presses, and you might hit some rough spots (or bugs) when using it, but it's your best option if you can make it work (if not, please file bugs or complain).

    If you can't use netstandard2 and are targeting XM Full, I would compile against net45 or net46. If you are using Modern, you'll need to specially compile either on Windows or against on the Mac.

    Make sense?

Sign In or Register to comment.