顯示具有 Article - Skills for Linux - Ubuntu 標籤的文章。 顯示所有文章
顯示具有 Article - Skills for Linux - Ubuntu 標籤的文章。 顯示所有文章

星期三, 6月 09, 2010

Installing and using mono on Ubuntu

英文來源

Two of the most popular topics on Builder AU, and indeed in the wider industry, is Microsoft's .NET framework and Linux development and administration.

Most of the time the two are in conflict, and it's rare to find a developer who needs to know about both. A lot of people aren't aware that you can combine the two, however, by using the Open Source mono project. This article will get you started on installing mono and running basic .NET applications on Linux

Firstly you'll need to install the base mono package using apt-get. It is a good idea to install two other packages at this point: monodevelop -- an interactive mono development environment similar in some ways to Visual Studio .NET (although nowhere near as sophisticated), and monodoc which provides help and technical documentation.

Just start up a root terminal and type:

% apt-get install mono monodevelop monodoc



When that's finished you've got a mono implementation ready to go, but while you're at it, you may as well include some of the add ons you'll need.

% apt-get install mono-utils mono-xsp monodoc-http

mono-utils provides some command line utilities that are useful if you'll be doing part of your development from the terminal. monodoc-http provides the monodoc manuals as a Web service, which requires the mono-xsp standalone Web server to operate. mono contains mcs the mono C# compiler, but it only compiles .NET 1.1 code, if you want to use the features of .NET 2.0 C# (such as the extremely helpful generics) then you'll need gmcs:

% apt-get install mono-gmcs

If you're planning to use monodevelop to write your code, then you can install a few more packages for SVN, Java, NUnit, Boo and MonoQuery support:

% apt-get install monodevelop-versioncontrol monodevelop-java monodevelop-nunit monodevelop-boo monodevelop-query

Likewise, if you're planning to use monodoc (strongly recommended) you can install manuals for whichever toolkits you'll be using:

% apt-get install monodoc-nunit-manual monodoc-ipod-manual monodoc-gtk2.0-manual


Before we get started on the code, let's take a look at some of the tools we've just installed. The monodoc browser lets you view the mono related manuals you have installed, including the useful C# language specification reference.



Or, if you'd prefer, you can read the documentation in your Web browser. The monodoc-http program starts up an XSP server that runs locally, allowing you to connect to it in any Web browser:



You can also start up the monodevelop IDE now if you wish, although you won't need anything that powerful for the examples we'll be looking at.



Now let's check that the whole thing is working by trying out some code. Take the standard C# Hello World program:

using System;
namespace Hello {
 class HelloWorld {
  public static void Main(string[] args) {
   Console.WriteLine("Hello World!");
  }
 }
}

Compile it using mcs and run it with the command mono. And the result:



That works, but it's a completely trivial example, and it doesn't include the most used part of .NET: Windows Forms. Let's see if a simple Windows Forms application will work. First make sure that you've got the relevant libraries installed:

% apt-get install libmono-winforms1.0-cil libmono-winforms2.0-cil

Now the source code:

using System;
using System.Windows.Forms;

namespace HelloClickWorld {
 public class Hello : Form {
  public static void Main (string[] args) {
   Application.Run (new Hello ());
  }

  public Hello ()
  {
   Button button = new Button ();
   button.Text = "Click...";
   button.Click += new EventHandler (Button_Click);
   Controls.Add (button);
  }

  private void Button_Click (object sender, EventArgs e)
  {
   MessageBox.Show ("Hello Click World!");
  }
 }
}

Compiling to assembly this time is a little more complicated, since you need to tell the C# compiler to include the library for Windows Forms:

% mcs -r:System.Windows.Forms hiclickworld.cs
% mono hiclickworld.exe



Finally we need to make sure ASP.NET will work just as well. Save the following as index.aspx:


Then start an xsp server in that directory.



Finally, point your Web browser at http://localhost:8080/ and check out your brand new Linux-built ASP.NET site:



If everything is working so far you've got a completely functioning mono installation, and you should be able to build applications on either Linux or Windows and deploy them on either system.

Be warned, mono is not a perfect replacement, there are parts of the .NET framework currently not implemented, particularly in the area of Windows Forms, so be very careful if you're looking to implement something complicated in mono, or migrate an existing .NET project.

在Ubuntu上執行.Net開發的程式

http://blog.colorbase.tw/programming/516

今天看了 Installing and using mono on Ubuntu 這篇文章之後,測試了一下在Ubuntu中執行.Net的程式

該篇文章對Mono on Ubuntu 講的非常詳細,其中包括如何在Ubuntu中透過mono附帶的編譯器,編譯.Net程式

讓Ubuntu支援.Net WindowForms程式

該文作者是在Ubuntu底下,利用Mono的編譯器進行編譯,因此裝了許多的套件,但如果開發環境是在WIndows底下,而且覺得用命令列編譯 太麻煩,其實只要安裝mono、libmono-winforms1.0-cil、libmono-winforms2.0-cil三個套件,就可以直接 執行已經在Windows底下編譯好的.Net程式,因為在Windows有更好用的 MS Visual Studio跟SharpDevelop等RAD工具,確實可以省下很多麻煩。

Ubuntu中Mono的安裝指令為:

sudo apt-get install mono
sudo apt-get install libmono-winforms1.0-cil libmono-winforms2.0-cil

又或者使用Ubuntu的Synaptic套件管理程式來安裝更方便(用慣GUI介面的人 XD)

小小測試

我在SharpDevelop中使用C#寫了一些簡單的小東西來做測試,GUI的部份只使用最基本的WindowForms元件,編譯完成後,直接拿到Ubuntu底下,輸入:

mono 執行檔名.exe

該測試程式中使用了以下的.Net套件

  • System
  • System.Collections.Generic
  • System.Drawing
  • System.Windows.Forms
  • System.Net
  • System.Threading
  • System.Collections
  • System.Xml
  • System.IO
  • System.Text

執行結果,各個功能執行無誤,執行畫面如下:

如同該篇文章所說,Mono並無支援所有的WindowForms元件,後來又測試了使用ToolTip元件,發現無法執行,原因似乎是不支援氣泡提示。

結論

雖然很遺憾Mono仍尚未完全支援.Net所提供的套件,但是以目前支援的程度所能達到的應用,應該可以說數不完了。

Ubuntu Server 的設定路徑

http://ubuntufish.blogspot.com/2008/04/ubuntu-server.html

Ubuntu Apache設定檔(http.conf)位置:
/etc/apache2/httpd.conf
/etc/apache2/apache2.conf
設定網頁位置、網址等基本
/etc/apache2/sites-available/default
加入 rewrite mode
/etc/apache2/mods-enabled$ sudo ln -s ../mods-available/rewrite.load rewrite.load
網頁預設目錄:/var/www

Ubuntu MySQL設定檔(my.cnf)位置:
/etc/mysql/my.cnf
資料庫預設目錄:/var/lib/mysql

Ubuntu PHP設定檔(php.ini)位置:
/etc/php5/apache2/php.ini

Ubuntu 安裝新軟體之簽章問題

http://ubuntufish.blogspot.com/search/label/Ubuntu

ubuntu在更新或加入新軟體時,時而出現
==============================================================
W: GPG error: http://ppa.launchpad.net jaunty Release: 由於無法
取得它們的公鑰,以下簽章無法進行驗證: NO_PUBKE 6AF0E1940624A220
===============================================================


解決方式:
===============================================================
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 6AF0E1940624A220
===============================================================

紅色字代表公鑰,每一軟體的公鑰不同,依每次出現公鑰取代之.