MonoDevelop: is it possible to switch PCL's compiler?
Asked Answered
P

2

10

We are starting a cross-platform project to be deployed to Android and iOS. Obviously, a lot of code is to be shared between the two, and some of the code relies heavily on the .NET framework items, like sqlite-net library does.

The best way (afaik) to share the code between 2 projects is to use a PCL – this way it is possible to reference the project with shared code from both iOS and Android projects in a solution and have everything re-compiled and linked in a nice manner.

However, a PCL created in MonoDevelop is compiled with gmcs compiler and some of external dependencies fail to be built in this case (i.e. the framework used in this case lacks System.Func<T, TResult>, providing only System.Func<T1, T2, ..., T9, TResult>). MonoTouch's compiler (smcs), in its turn, is able to compile the PCL perfectly (proven by replacing gmcs binary with smcs binary). From what I've found after a bit of googling, gmcs uses 2.0 .NET framework, while smcs uses smth called 2.1 framework, which is in fact a cutted mixture of more recent .NETs.

Here comes the question: is it possible to specify which compiler to use while building PCL (as a dependency of another project) in MonoDevelop?

Patrolman answered 20/8, 2012 at 16:14 Comment(0)
M
16

Mono does not yet have an implementation of the actual PCL libraries. For now, it has a dummy Microsoft.Portable.CSharp.targets file that instead overrides the framework and targets to build the library against MonoTouch, Mono for Android or .NET 4.0, in that order, depending what's installed.

It looks like there's bug in the codepath that uses the MonoTouch framework - it's using the default common targets, Microsoft.CSharp.targets, without overriding the compiler to use the MonoTouch-specific version of the C# compiler. This is necessary because Mono's C# compiler is currently framework-specific (though this is fixed in Mono 2.12, which is in alpha).

You may be able to fix this by editing the file /Library/Frameworks/Mono.framework/Versions/Current/lib/mono/xbuild/Microsoft/Portable/v4.0/Microsoft.Portable.CSharp.targets, finding the PropertyGroup that sets

<TargetFrameworkIdentifier>MonoTouch</TargetFrameworkIdentifier>

And to it, adding the lines:

<CscToolExe>smcs</CscToolExe>
<CscToolPath>/Developer/MonoTouch/usr/bin</CscToolPath>
Micronesia answered 21/8, 2012 at 20:31 Comment(4)
By the way, what are the plans re PCL? I do understand that at the moment it is just a stab, but it works just great in cases when you need to share some code between iOS and Android apps. I mean you can reference a PCL's project, and it will be build on a platform you are compiling at the moment. As far as I understand, once "true" PCL come to Mono, this will be dropped, and every PCL will be built using the "standard" compiler, which might lack some features/libs/whatever present in MonoTouch/MonoForAndroid. Are there any plans on smth like dependent projects (hope it is clear what I mean)?Patrolman
Lots of plans/ideas - e.g. true PCL support, new PCL project that has the MfA/MT subset, project linker, etc - but nothing concrete yet.Micronesia
Thanks for this - I think it really really really helps with the bugs I've been struggling on bugzilla.xamarin.com/show_bug.cgi?id=5329 and bugzilla.xamarin.com/show_bug.cgi?id=5329 and beyond... as Anton said - you're a fckng hero :)Falcongentle
Here's a link to the fixed Microsoft.Portable.CSharp.targets file: files.xamarin.com/~jeff/Microsoft.Portable.CSharp.targetsMaximomaximum
T
1

I know this is an old question, but it appears that Portable Class Library (PCL) support was added to Mono in version 3.0.x, see the Release Notes for details, particularly version 3.0.8 :

Added PCL support to xbuild, mono’s MSBuild implementation.

Tract answered 16/1, 2015 at 20:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.