.NET/MONO 交叉编译的最佳实践 [英] Best practices for .NET/MONO cross compiling

查看:13
本文介绍了.NET/MONO 交叉编译的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写可在 .NET(Windows)和 Mono(Linux)上交叉编译的代码的最佳实践是什么?尽管我对 .NET 非常熟悉,但我对 Mono 及其所有问题的经验并不丰富.有没有人看过一篇关于这方面的好博客文章或最佳实践论文,但我无法挖掘出来?我会坚持使用 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.

我首先关心的是互操作,因为我需要调用一些本机代码.接下来是处理诸如 Mono.XXX 之类的命名空间的最佳方法.我应该使用一堆#if吗?隔离每个平台程序集中的代码?

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?

任何有关架构和设计的建议将不胜感激!如果您有在 Visual Studio(任何版本)中为 Linux/Mono 进行交叉编译的经验,我也会对此感兴趣.

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.

推荐答案

最大的问题是坚持使用 Mono 支持的 API.在 Mono 中使用 Visual Studio 集成 支持对此有很大帮助,因为您可以针对 Mono整个时间,在所有平台上.

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) 使用#if - 我会避免这种情况,并且更喜欢使用可扩展性模型.Mono 支持 托管可扩展性框架,它提供了一种在运行时插入"平台特定代码的好方法.

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.

这篇关于.NET/MONO 交叉编译的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆