< meta http-equiv="description" content="每个库文件下,又有自己的.net版本号。如果用的是.net 2.0那么4.0.0.0那个目录就可以删除,如果你想问为什么没有3.0、3.5的库。答案是3.0和3.5用的是2.0的库。而1.0的库由于年代久远,Mono2已经不支持了。如果需要的话,可以下载Mono早期的版本"/>

让NET C# 程序独立运行(脱离 .NET Framework运行,绿色运行)

[来源] 达内    [编辑] 达内   [时间]2012-09-19

每个库文件下,又有自己的.net版本号。如果用的是.net 2.0那么4.0.0.0那个目录就可以删除,如果你想问为什么没有3.0、3.5的库。答案是3.0和3.5用的是2.0的库。而1.0的库由于年代久远,Mono2已经不支持了。如果需要的话,可以下载Mono早期的版本

我觉的MS的.net方案其实很不错。C#呢,用现在流行的话来说“很给力”!

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">但是.net版本众多。而且.NET Framework框架很大。拖着一个大大的.net Framework总是让人很郁闷。

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">我也碰到了这个让人郁闷的问题。

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">在网上找呀找呀。找到另一个.NET Framework 替代方案。Mono。

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 下载地址为:http://www.go-mono.com/mono-downloads/download.html

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">Mono2.10.2版本支持.net 2.0至4.0版本。

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">下载回来后安装一下,我傻了居然有336M。而且Mono的居然方式是命令行的。仍然让人很郁闷。

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">算了,既然安装了。找找资料吧。

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">终于看到了前人的工作结晶。

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">Mono运行C#程序所要的库资源其实不多。

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">只要C:\Program Files\Mono-2.10.2\bin目录下的。(以下均以C:\Program Files\Mono-2.10.2目录为根目录)

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">mono.exe,mono-2.0.dll

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">lib\mono\.net版本号\mscorlib.dll。我这里用的是.net 2.0版本。

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">lib\mono\gac\目录下的必要库文件。 WinForm程序只要这5个库就行了。

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 每个库文件下,又有自己的.net版本号。如果用的是.net 2.0那么4.0.0.0那个目录就可以删除, 如果你想问为什么没有3.0、3.5的库。答案是3.0和3.5用的是2.0的库。而1.0的库由于年代久远,Mono2已经不支持了。如果需要的话,可以下载Mono早期的版本。

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 另外我发现库文件下,有同名的.mdb文件。

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 那个.mdb文件删除掉对程序没什么影响。所以通通删除掉。

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 经过层层删除,最后剩下的那几个文件,加起来也就8M多点。而程序一点问题也没有。完美运行!

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">发行软件的时候用RAR压缩一下,程序只有3M多。很完美了!

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">可是我怎么知道。。我的程序具体要用到哪些库呢?

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 答案是:不知道。去记程序要用到哪些库太累了。我才不会去记呢。我有一个偷懒的办法。新建一个文件夹,先将 不变的文件放好。bin目录下的mono.exe,mono-2.0.dll,lib\mono\.net版本号\mscorlib.dll。最后将Mono下lib\mono\gac中所有的库文件拷贝过来。运行编译好的C#程序。现在可以开始疯狂的删除了,碰到不能删除的文件,剩下的就是我们的程序要用的库了。此方法简单高效,百试不爽。

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 但是接下来还有个问题,Mono那个讨厌的命令行。还有如果人家电脑上装了.net库呢?用MS自家的.net不是更好么?于是我参考Mono官网,用C和windows api写了一个.net的引导程序。可以根据用设定来选择.net版本,如果客户电脑已经安装用户指定版本,则优先使用MS的.net,如果不存在则用Mono引导程序。

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">这个引导程序使用config.ini做为配置文件。

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">C#_Version=2.0                    //.net版本号,共有4个值:2.0、3.5、4.0C、4.0F

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">C#_AppName=MyBooks.exe   //预启动的应用程序名称

< p style="margin: 5px auto; padding: 0px; text-indent: 0px; color: rgb(17, 17, 17); font-family: verdana, arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 23px; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 这个引导程序,在32位XP下使用VS 2008编译。因为是用windows api编写,没有额外的库。所以理论上32位的系统应当都能使用,64位的没试过。这个引导程序测试.net 2.0项目和.net 4.0项目都没问题。这个程序直接调用了mono-2.0.dll。所以Mono.exe也就没用了。下面给出我的测试项目,直接运行monologin.exe即可。效果我还是很满意的。同时欢迎交流!

资源下载