RHEL5下用mono运行.NET控制台程序

1.安装mono-2.10.2

[root@localhost soft]#wget http://ftp.novell.com/pub/mono/sources/mono/mono-2.10.2.tar.bz2
[root@localhost soft]#tar -jxvf mono-2.10.2.tar.bz2
[root@localhost soft]#cd mono-2.10.2
[root@localhost mono-2.10.2]#./configure --prefix=/opt/mono
[root@localhost mono-2.10.2]#make&&make install
[root@localhost mono-2.10.2]#echo export PKG_CONFIG_PATH=/opt/mono/lib/pkgconfig:$PKG_CONFIG_PATH>>~/.bash_profile
[root@localhost mono-2.10.2]#echo export PATH=/opt/mono/bin:$PATH>>~/.bash_profile
[root@localhost mono-2.10.2]#source ~/.bash_profile

安装时间有点漫长,接下来验证下是否安装成功:

[root@localhost mono-2.10.2]#mono -V
Mono JIT compiler version 2.10.2 (tarball 2011年 06月 24日 星期五 10:27:41 CST)
Copyright (C) 2002-2011 Novell, Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  x86
        Disabled:      none
        Misc:          softdebug
        LLVM:          supported, not enabled.
        GC:            Included Boehm (with typed GC and Parallel Mark)

这说明安装成功了。若是想卸载,运行make uninstall即可。

2.运行.NET控制台程序

Program.cs:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("请输入一个路径:");
            string path = Console.ReadLine();
            string[] files = Directory.GetFiles(path);
            foreach(string item in files)
                Console.WriteLine(item);

            Console.ReadKey();
        }
    }

}

用mono运行程序:
[root@localhost soft]# wget ftp://192.168.0.111/file.exe
--12:01:59--  ftp://192.168.0.111/file.exe
           => `file.exe'
Connecting to 192.168.0.111:21... 已连接。
正在以 anonymous 登录 ... 登录成功!
==> SYST ... 完成。    ==> PWD ... 完成。
==> TYPE I ... 完成。  ==> 不需要 CWD。
==> SIZE file.exe ... 5120
==> PASV ... 完成。    ==> RETR file.exe ... 完成。
长度:5120 (5.0K)

100%[=======================================>] 5,120       --.-K/s   in 0s

12:02:00 (111 MB/s) - `file.exe' saved [5120]

[root@localhost soft]# mono file.exe
请输入一个路径:/soft/
/soft/Firefox-3.6.17.tar.bz2
/soft/Firefox-latest.tar.bz2
/soft/console.exe
/soft/file.exe
/soft/flash-plugin-10.3.181.26-release.i386.rpm
/soft/install_flash_player_10_linux.tar.gz
/soft/linuxqq-v1.0.2-beta1.i386.rpm
/soft/linuxqq_v1.0.2_i386.tar.gz
/soft/mono-2.10.2.tar.bz2
/soft/winforms.exe

[root@localhost soft]#

可以了

参考资料

[1].编译安装mono 让linux也支持.NET应用:http://www.kaychen.cn/mono_install.html

评论: 0 | 引用: 0 | 查看次数: 4938
发表评论
登录后再发表评论!