mono

Mono为何能跨平台?聊聊CIL(MSIL)

做~自己de王妃 提交于 2019-12-30 07:24:06
前言: 项目紧赶慢赶总算在年前有了一些成绩,所以沉寂了几周之后,小匹夫也终于有时间写点东西了。以前匹夫写过一篇文章,对CIL做了一个简单地介绍,不过不知道各位看官看的是否过瘾,至少小匹夫觉得很不过瘾。所以决定写几篇关于CIL的文章,即和各位看官一起进行个交流,同时也是匹夫自己总结和巩固一下这些知识点。俗话说的好, “万事开头,Hello World” ,那么作为匹夫总结CIL的第一篇文章,就从 Hello World 开始吧。当然,正式开始写CIL代码之前,我们还有点闲话要说,那就是运行时的选择为何是它? 为何是CIL ?而 CIL为何又是基于堆栈 的?内存或者寄存器难道不是更理想的选择吗? 为何是CIL? 开始正文内容之前,匹夫带领大家先回顾一下《 Mono为何能跨平台?聊聊CIL(MSIL) 》的简要内容:首先,用C#写的代码被C#的编译器编译成CIL(当然除了C#还有很多其他的语言,比如VB等等),之后再有JIT编译器在程序运行时即时编译或者AOT(或者NGEN)进行提前编译将CIL代码编译成对应平台的机器码,最后运行在平台上的便是机器码。小匹夫在那篇文章中提过,首先将各种不同的语言都统一编译成CIL,再由CIL编译成各个平台的机器码是跨平台的基础。那么仔细想想,一定有人会提出这样的疑问,直接从C#编译到机器码,省略掉“多余”的中间语言,是不是也可行呢?这个问题的确值得讨论

PFX/PKCS12 to SNK conversion for mono

家住魔仙堡 提交于 2019-12-30 06:38:07
问题 This is follow up on Mono xbuild error CS1548 - key file has incorrect format Hi, I have an application that is written in C# using VS2008. At present we are porting this app to Mac using Mono. I have tried to extract the key from the pfx file. First I used `sn -pc key.pfx key.snk` this gave me an error of 'Failed to extract public key for key pair -- Keyset does not exist'. I then used `sn -p key.pfx key.snk` this created the snk file that I wanted. I then in mono selected the project Option

Running F# code with Mono

白昼怎懂夜的黑 提交于 2019-12-30 06:23:09
问题 I have F# 2.0.0 installed, and use mono 2.8. let rec fib n = match n with | 1 | 2 -> 1 | n -> fib(n-1) + fib(n-2) let n = 40 let x = fib(n) printfn "%d" x I compiled this code with fsc.exe to get fib.exe. Running this with mono fib.exe gives me this error. mono fact.exe Could not load file or assembly 'FSharp.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Unhandled Exception: System.TypeLoadException: Could not load type '.$Factorial' from

C# compiled in mono - Detect OS

旧巷老猫 提交于 2019-12-30 05:57:08
问题 I am trying to get a C# app running under OSX which is not exactly pain free. To work around some of the issues in the short term, I am thinking of setting up some specific rules when it is running in OSX. But... What can I use to determine whether the app is running under Windows or OSX? 回答1: From the Mono wiki (in my experience, OSX is identified as Unix): int p = (int) Environment.OSVersion.Platform; if ((p == 4) || (p == 128)) { Console.WriteLine ("Running on Unix"); } else { Console

HttpWebRequest NameResolutionFailure exception in .NET (with Mono on Ubuntu)

旧街凉风 提交于 2019-12-30 03:56:06
问题 I have a .NET program running on Ubuntu via Mono 2.10 The program downloads a webpage via an HttpWebRequest every minute or so which works fine most of the time: String result; WebResponse objResponse; WebRequest objRequest = System.Net.HttpWebRequest.Create(url); using (objResponse = objRequest.GetResponse()) { using (StreamReader sr = new StreamReader(objResponse.GetResponseStream())) { result = sr.ReadToEnd(); // Close and clean up the StreamReader sr.Close(); } } The problem is that after

Create C# executable with mkbundle on windows

放肆的年华 提交于 2019-12-30 03:27:05
问题 Im trying to create an executable from a console application. I have installed mono,cygwin (mingw-gcc, mingw-zlib1, mingw-zlib-devel, pkg-config) and I have added the following lines to my .bashrc file export PKG_CONFIG_PATH=/cygdrive/c/progra~1/Mono-3.2.3/lib/pkgconfig export PATH=$PATH:/cygdrive/c/progra~1/Mono-3.2.3/bin export CC="i686-pc-mingw32-gcc -U _WIN32" But everytime I try to use mkbundle I receive the following message Is there a way to make mkbundle work properly on windows.? (Im

Does Mono Mkbundle Produce Native Code

て烟熏妆下的殇ゞ 提交于 2019-12-30 01:26:58
问题 The normal EXE's generated by mono are in IL.I want to generate Native Executable,does using mkbundle produce native Exe's or should i use Mono AOT. 回答1: Yes, mkbundle produces native executables. For example, on Linux, here is my .NET assembly: file Agent.exe Agent.exe: PE32 executable (console) Intel 80386, Mono/.Net assembly, for MS Windows I tell mkbundle to compile it to a native executable (here I have to add Common.dll which is a dependency to my Agent.exe assembly): mkbundle --deps -o

Is WPF on Linux (already) possible?

时光毁灭记忆、已成空白 提交于 2019-12-29 12:15:00
问题 I love programming with .NET, especially C# 3.0, .NET 3.5 and WPF. But what I especially like is that with Mono .NET is really platform-independent. Now I heard about the Olive Project in Mono. I couldn't find some kind of Beta. Does it already work? Have any of you made any experiences with it? Edit: I know about Moonlight. But I want a standalone WPF application. And because of Moonlight I hope WPF on Linux will become true. 回答1: You'll have better luck working with Moonlight, which targets

Is WPF on Linux (already) possible?

笑着哭i 提交于 2019-12-29 12:14:10
问题 I love programming with .NET, especially C# 3.0, .NET 3.5 and WPF. But what I especially like is that with Mono .NET is really platform-independent. Now I heard about the Olive Project in Mono. I couldn't find some kind of Beta. Does it already work? Have any of you made any experiences with it? Edit: I know about Moonlight. But I want a standalone WPF application. And because of Moonlight I hope WPF on Linux will become true. 回答1: You'll have better luck working with Moonlight, which targets

How do I use Travis-CI with C# or F#

天涯浪子 提交于 2019-12-29 10:05:18
问题 Travis CI continuous integration service officially supports many languages, but not C# or F#. Can I use it with my .net projects? 回答1: Travis CI now supports C#. Quoting liberally from that page: Overview The setup for C#, F#, and Visual Basic projects looks like this: language: csharp solution: solution-name.sln mono: - latest - 3.12.0 - 3.10.0 Script By default Travis will run xbuild solution-name.sln. Xbuild is a build tool designed to be an implementation for Microsoft's MSBuild tool. To