Linux 的 Mono(tm) 二進位制核心支援

要配置 Linux 以自動執行基於 Mono 的 .NET 二進位制檔案(以 .exe 檔案的形式),而無需使用 mono CLR 包裝器,可以使用 BINFMT_MISC 核心支援。

在完成以下操作後,這將允許您像執行任何其他程式一樣執行基於 Mono 的 .NET 二進位制檔案

  1. 您必須首先安裝 Mono CLR 支援,可以透過下載二進位制包、原始碼 tarball 或從 Git 安裝。 幾個發行版的二進位制包可以在以下位置找到

    編譯 Mono 的說明可以在以下位置找到

    安裝 Mono CLR 支援後,只需檢查 /usr/bin/mono(可能位於其他位置,例如 /usr/local/bin/mono)是否正常工作。

  2. 您必須將 BINFMT_MISC 編譯為模組或編譯到核心中 (CONFIG_BINFMT_MISC) 並正確設定它。 如果您選擇將其編譯為模組,則必須使用 modprobe/insmod 手動插入它,因為 binfmt_misc 不容易支援 kmod。 閱讀此目錄中的檔案 binfmt_misc.txt 以瞭解有關配置過程的更多資訊。

  3. 將以下條目新增到 /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
    
  4. 檢查是否可以直接從命令提示符啟動 .exe 檔案,而無需包裝器指令碼即可執行 .exe 二進位制檔案,例如

    /usr/bin/xsd.exe
    

    注意

    如果出現許可權被拒絕錯誤,請檢查 .exe 檔案是否具有執行許可權。