对于.NET / MONO交叉编译的最佳实践NET、MONO

2023-09-03 10:08:49 作者:软妹通缉犯

什么是写作code,它可以交叉编译的.NET(视窗)和Mono(Linux版)的最佳实践?虽然我很熟悉.NET,我不是说经历了单声道和所有的陷阱。有没有人看到一个很好的博客文章或最佳实践白皮书在此,我一直没能挖?我会坚持用C#3.0级功能。

What are the best practices for writing code that can be cross compiled on .NET (windows) and Mono (linux)? Although I am very familiar with .NET, I am not that experienced in Mono and all its gotchas. Has anyone seen a good blog post or best practices paper on this, which I have not been able to dig up? I would be sticking with C# 3.0 level features.

的事情,关我的事首先是互操作的,因为我需要调用一些本地code。 下一步将是处理命名空间的最佳方式,如Mono.XXX。我应该用一串#如果吗?隔离code在每个平台组件?

Things that concern me is first of all Interop, since I would need to call some native code. Next would be the best ways to handle namespaces such as Mono.XXX. Should I be using a bunch of #if? Isolate the code in per-platform assemblies?

任何有关架构和设计建议,将不胜AP preciated! 如果你有过交叉编译的Linux /单声道在Visual Studio(所有版本)的经验,我也有兴趣的。

Any suggestions regarding architecture and design would be greatly appreciated! If you have had any experience in cross compiling for Linux/Mono in visual studio (any version), I would also be interested in that.

推荐答案

最大的问题是粘到单声道,支持的API。使用 Visual Studio集成支持单声道可以有很大的帮助这个问题,因为你可以针对单整时间,在所有平台。

The biggest issues are sticking to the Mono-supported APIs. Using the Visual Studio Integration support in Mono can help a lot with this, since you can target Mono the entire time, on all platforms.

有关的具体问题:

1)互操作 - 你需要坚持的P / Invoke。尝试隔离此为独立的,特定平台组件。这导致2:

1) Interop - You'll need to stick to P/Invoke. Try to isolate this into separate, platform specific assemblies. This leads to 2:

2)使用#如果 - 我会避免这一点,preFER使用扩展模式。单声道支持托管扩展性框架,它提供了在运行时插入平台特定的code的好办法。

2) Using #if - I would avoid this, and prefer to use an extensibility model. Mono supports the Managed Extensibility Framework, which provides a good way to "plug in" platform specific code at runtime.