简体   繁体   English

MonoDevelop:是否可以切换PCL的编译器?

[英]MonoDevelop: is it possible to switch PCL's compiler?

We are starting a cross-platform project to be deployed to Android and iOS. 我们正在启动一个跨平台项目,以部署到Android和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. 显然,很多代码都要在两者之间共享,而一些代码在很大程度上依赖于.NET框架项,就像sqlite-net库那样。

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. 在两个项目之间共享代码的最佳方式(afaik)是使用PCL - 这样就可以在解决方案中使用来自iOS和Android项目的共享代码来引用项目,并将所有内容重新编译并链接到一个很好的方式。

However, a PCL created in MonoDevelop is compiled with gmcs compiler and some of external dependencies fail to be built in this case (ie the framework used in this case lacks System.Func<T, TResult> , providing only System.Func<T1, T2, ..., T9, TResult> ). 但是,使用gmcs编译器编译在MonoDevelop中创建的PCL,并且在这种情况下无法构建一些外部依赖项(即,在这种情况下使用的框架缺少System.Func<T, TResult> ,仅提供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). 反过来,MonoTouch的编译器(smcs)能够完美地编译PCL(通过用smcs二进制替换gmcs二进制文件证明)。 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. 从谷歌搜索后发现,gmcs使用2.0 .NET框架,而smcs使用名为2.1框架的smth,这实际上是更新的.NET的混合体。

Here comes the question: is it possible to specify which compiler to use while building PCL (as a dependency of another project) in MonoDevelop? 这里有一个问题:在MonoDevelop中构建PCL(作为另一个项目的依赖项)时,是否可以指定使用哪个编译器?

Mono does not yet have an implementation of the actual PCL libraries. Mono尚未实现实际的PCL库。 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. 目前,它有一个虚拟的Microsoft.Portable.CSharp.targets文件 ,它改为覆盖框架和目标,根据安装的顺序,依次按照MonoTouch,Mono for Android或.NET 4.0构建库。

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. 看起来代码路径中存在使用MonoTouch框架的错误 - 它使用默认的公共目标Microsoft.CSharp.targets,而不会覆盖编译器以使用特定于MonoTouch的C#编译器版本。 This is necessary because Mono's C# compiler is currently framework-specific (though this is fixed in Mono 2.12, which is in alpha). 这是必要的,因为Mono的C#编译器目前是特定于框架的(尽管这在Mono 2.12中是固定的,它是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 您可以通过编辑文件/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/xbuild/Microsoft/Portable/v4.0/Microsoft.Portable.CSharp.targets来修复此问题,找到PropertyGroup,套

<TargetFrameworkIdentifier>MonoTouch</TargetFrameworkIdentifier>

And to it, adding the lines: 并且,添加以下行:

<CscToolExe>smcs</CscToolExe>
<CscToolPath>/Developer/MonoTouch/usr/bin</CscToolPath>

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 : 我知道这是一个老问题,但似乎在3.0.x版本的Mono中添加了可移植类库(PCL)支持,有关详细信息,请参阅发行说明 ,特别是3.0.8版:

Added PCL support to xbuild, mono's MSBuild implementation. 添加了对xbuild,mono的MSBuild实现的PCL支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM