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

时间:2022-07-05 12:15:08

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.

编写可以在.NET(windows)和Mono(linux)上交叉编译的代码的最佳实践是什么?虽然我对.NET非常熟悉,但我对Mono及其所有问题都没有经验。有没有人看过关于这个的好博客文章或最佳实践论文,我还没有能够挖掘出来?我会坚持使用C#3.0级别的功能。

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?

与我有关的事情首先是Interop,因为我需要调用一些本机代码。接下来是处理名称空间的最佳方法,例如Mono.XXX。我应该使用一堆#if吗?隔离每个平台程序集中的代码?

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的经验,我也会对此感兴趣。

5 个解决方案

#1


7  

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.

最大的问题是坚持Mono支持的API。使用Mono中的Visual Studio Integration支持可以为此提供很多帮助,因为您可以在所有平台上始终以Mono为目标。

For your specific questions:

针对您的具体问题:

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

1)互操作 - 你需要坚持P / Invoke。尝试将其隔离到单独的平台特定程序集中。这导致2:

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.

2)使用#if - 我会避免这种情况,并且更喜欢使用可扩展性模型。 Mono支持Managed Extensibility Framework,它提供了一种在运行时“插入”特定于平台的代码的好方法。

#2


3  

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。

#3


2  

Check out The Mono Migration Analyzer

查看Mono迁移分析器

#4


2  

The Mono project provides a document with portability guidelines. That is a pretty good place to start.

Mono项目提供了一个包含可移植性指南的文档。这是一个非常好的起点。

#5


0  

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.

从近一年开始依靠软调试器也是一件好事。

#1


7  

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.

最大的问题是坚持Mono支持的API。使用Mono中的Visual Studio Integration支持可以为此提供很多帮助,因为您可以在所有平台上始终以Mono为目标。

For your specific questions:

针对您的具体问题:

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

1)互操作 - 你需要坚持P / Invoke。尝试将其隔离到单独的平台特定程序集中。这导致2:

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.

2)使用#if - 我会避免这种情况,并且更喜欢使用可扩展性模型。 Mono支持Managed Extensibility Framework,它提供了一种在运行时“插入”特定于平台的代码的好方法。

#2


3  

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。

#3


2  

Check out The Mono Migration Analyzer

查看Mono迁移分析器

#4


2  

The Mono project provides a document with portability guidelines. That is a pretty good place to start.

Mono项目提供了一个包含可移植性指南的文档。这是一个非常好的起点。

#5


0  

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.

从近一年开始依靠软调试器也是一件好事。