简体   繁体   English

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

[英]Best practices for .NET/MONO cross compiling

What are the best practices for writing code that can be cross compiled on .NET (windows) and Mono (linux)? 编写可以在.NET(windows)和Mono(linux)上交叉编译的代码的最佳实践是什么? Although I am very familiar with .NET, I am not that experienced in Mono and all its gotchas. 虽然我对.NET非常熟悉,但我对Mono及其所有问题都没有经验。 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. 我会坚持使用C#3.0级别的功能。

Things that concern me is first of all Interop, since I would need to call some native code. 与我有关的事情首先是Interop,因为我需要调用一些本机代码。 Next would be the best ways to handle namespaces such as Mono.XXX. 接下来是处理名称空间的最佳方法,例如Mono.XXX。 Should I be using a bunch of #if? 我应该使用一堆#if吗? Isolate the code in per-platform assemblies? 隔离每个平台程序集中的代码?

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. 如果你在visual studio(任何版本)的Linux / Mono交叉编译方面有任何经验,我也会对此感兴趣。

The biggest issues are sticking to the Mono-supported APIs. 最大的问题是坚持Mono支持的API。 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. 使用Mono中的Visual Studio Integration支持可以为此提供很多帮助,因为您可以在所有平台上始终以Mono为目标。

For your specific questions: 针对您的具体问题:

1) Interop - You'll need to stick to P/Invoke. 1)互操作 - 你需要坚持P / Invoke。 Try to isolate this into separate, platform specific assemblies. 尝试将其隔离到单独的平台特定程序集中。 This leads to 2: 这导致2:

2) Using #if - I would avoid this, and prefer to use an extensibility model. 2)使用#if - 我会避免这种情况,并且更喜欢使用可扩展性模型。 Mono supports the Managed Extensibility Framework , which provides a good way to "plug in" platform specific code at runtime. Mono支持Managed Extensibility Framework ,它提供了一种在运行时“插入”特定于平台的代码的好方法。

You should be interrested by Prebuild : 你应该被Prebuild感兴趣:

Prebuild is a cross-platform XML-driven pre-build tool which allows developers to easily generate project files for major IDE's and .NET development tools including: Visual Studio .NET 2002, 2003, 2005, SharpDevelop, MonoDevelop, NAnt and Autotools. Prebuild是一个跨平台的XML驱动的预构建工具,允许开发人员轻松生成主要IDE和.NET开发工具的项目文件,包括:Visual Studio .NET 2002,2003,2005,SharpDevelop,MonoDevelop,NAnt和Autotools。

The Mono project provides a document with portability guidelines . Mono项目提供了一个包含可移植性指南的文档。 That is a pretty good place to start. 这是一个非常好的起点。

We use MonoDevelop and Visual Studio for development but what's key is to keep around a good NAnt build script to build the entire thing on a single shot (Joel Spolsky's rules). 我们使用MonoDevelop和Visual Studio进行开发,但关键是要保留一个好的NAnt构建脚本来一次性构建整个事物(Joel Spolsky的规则)。

The main point IMO is to state very clear that the software has to be cross-platform, so it is not about "porting to linux/mono" but actually developing each iteration on the required platforms. IMO的主要观点是非常清楚地表明该软件必须是跨平台的,因此它不是“移植到linux / mono”,而是实际开发所需平台上的每次迭代。

We had to avoid some features at the beginning (using Mono/.NET for 5 years now for a commercial product) and we still stick to .NET Remoting, but that's not a big deal in multi-platform development in my opinion. 我们不得不在开始时避免使用某些功能(现在使用Mono / .NET 5年用于商业产品),我们仍然坚持使用.NET Remoting,但在我看来,这在多平台开发中并不是什么大问题。

Counting on the soft debugger since almost one year is also a great thing. 从近一年开始算上软调试器也是一件好事。

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

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