Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
331 views
in Technique[技术] by (71.8m points)

portable class library - MonoDevelop: is it possible to switch PCL's compiler?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...