Linux 的 Mono(tm) 二进制内核支持¶
要配置 Linux 以自动执行基于 Mono 的 .NET 二进制文件(即 .exe 文件),而无需使用 mono CLR 包装器,可以使用 BINFMT_MISC 内核支持。
完成以下步骤后,您就可以像执行其他程序一样执行基于 Mono 的 .NET 二进制文件
您必须首先安装 Mono CLR 支持,可以通过下载二进制包、源代码 tarball 或从 Git 安装。适用于多个发行版的二进制包可以在以下位置找到:
编译 Mono 的说明可以在以下位置找到:
一旦安装了 Mono CLR 支持,只需检查
/usr/bin/mono(它也可能位于其他位置,例如/usr/local/bin/mono)是否正常工作。您必须将 BINFMT_MISC 编译为模块或内置到内核中(
CONFIG_BINFMT_MISC),并进行正确设置。如果您选择将其编译为模块,则必须使用 modprobe/insmod 手动插入它,因为 binfmt_misc 无法轻易支持 kmod。阅读此目录中的binfmt_misc.txt文件以了解有关配置过程的更多信息。将以下条目添加到
/etc/rc.local或类似的脚本中,以便在系统启动时运行:# Insert BINFMT_MISC module into the kernel if [ ! -e /proc/sys/fs/binfmt_misc/register ]; then /sbin/modprobe binfmt_misc # Some distributions, like Fedora Core, perform # the following command automatically when the # binfmt_misc module is loaded into the kernel # or during normal boot up (systemd-based systems). # Thus, it is possible that the following line # is not needed at all. mount -t binfmt_misc none /proc/sys/fs/binfmt_misc fi # Register support for .NET CLR binaries if [ -e /proc/sys/fs/binfmt_misc/register ]; then # Replace /usr/bin/mono with the correct pathname to # the Mono CLR runtime (usually /usr/local/bin/mono # when compiling from sources or CVS). echo ':CLR:M::MZ::/usr/bin/mono:' > /proc/sys/fs/binfmt_misc/register else echo "No binfmt_misc support" exit 1 fi
检查
.exe二进制文件是否可以在不使用包装器脚本的情况下运行,只需直接从命令提示符启动.exe文件,例如:/usr/bin/xsd.exe
注意
如果失败并显示权限拒绝错误,请检查该
.exe文件是否具有执行权限。