HelloWorld ---.net on Linux!

zhaozj2021-02-16  37

As a .net developer, I have always had a wish, that is, let my software run - I can run in all the computer, no matter what the operating system it runs, no matter what it belongs to Which camp. I have always heard that mono (http://www.go-mono.org) is doing this effort, but truly let me walk into the cross-platform world is another nameless project - Dotgnu.

What is dotgnu?

As can be seen from the name, Dotgnu home GNU camp, its goal is to transplant the .NET environment to a variety of operational platforms headed by GNU / Linux, thereby realizing cross-platform .NET development. Currently, the project has been capable of supporting a variety of operating systems such as GNU / Linux, Windows, NetBSD, FreeBSD, Solaris, and Macos X. If you are interested in cross-platform development .NET application like me, please go to Dotgnu's homepage (http://www.dotgnu.org) to learn more about the situation, I am here. More introduced.

Hello World On Linux

Let us develop a real cross-platform .NET program, we write a simple helloworld bar :) In addition, since I only have both Windows and Linux environment on my machine, I can only demonstrate this The application of two platforms, if you have Mac OS, Solaris or other environments and interested in, then please help me to complete the transplant on other platforms :).

let's start. First, you need to configure a set of dotgnu runtime environments (just like configured .NET SDK). Download the latest installation files for free from Dotgnu website (about

210M

), Directly implementation. Of course, you can only download its source code and compile this machine, even get the latest version from CVS. After installation, add the absolute path of the BIN subdirectory in the installation directory to the PATH variable of the machine to facilitate call compilers and other auxiliary development tools.

After the development environment is set, it can be encoded. Please open your usual text editor in Windows, write a simple C # version Hello World as follows (I use Emacs):

You can compile it after you save it into helloWorld.cs. Because it is in the Windows operating system, you can use Microsoft's CSC or CSCC for dotgnu. The former is the most in daily contact, so I will demonstrate how to call CSCC. Run the following command in Emacs, run the following command (please make sure the directory where helloWorld.cs is the current directory):

Cscc -o helloworld.exe helloworld.cs

Where o indicates the name of the generated file. The entire usage is almost the same as Microsoft's CSC.

If the compilation is successful, you can run HelloWorld.exe next. Like compilation, since this is in the Windows operating system, you can have two ways to run it. The first is to run HelloWorld.exe directly in cmd.exe, which is the practice of running applications under Windows; of course, you can also try the Ilrun.exe tool provided by Dotgnu, which is to let the app offer in dotgnu. Run in the NET runtime environment. The calling method is as follows:

Ilrun HelloWorld

Run success:

Ok, since this code can compile and run under Windows, then we will get it compiled and run below the Linux, see the miracle can happen :) Open VMware, start the Red Hat Linux 9 virtual machine. Since the .NET program is required. Net runtime environment support, so we should also install the dotgnu environment below Linux. Dotgnu installation files provide different installation methods for different operating systems, follow the prompts to perform normal installation.

Next, please find the helloworld.cs file you have previously prepared (you can use the easiest way to build a network connection, you can also use the easiest way - copy things :), in Bash (if you installed other Different shells, such as CSH, operate slightly differently) Execution and Windows Same Compile Command:

Cscc -o helloworld.exe helloworld.cs

Note that Output files do not have to take the .exe suffix, here I just extends the habits under Windows.

If you have confiscated any error prompt, congratulations, compile success! Now you can run Ilrun to perform our helloWorld.exe:

Ilrun HelloWorld

Wow!

Since I added a logic that handles command line parameters in the source code, you can also enter some strings as you like this, and HelloWorld.exe will print them separately.

Ok, our lovely HelloWorld is really in the ground, truly .NET! If you are interested, you can also add different features, and test whether Dotgnu has putted your ability to care. In addition, one problem that all people most concerned is: Dotgnu's successful migration of system.windows.forms? The answer is yes! On the home page of Dotgnu, there is a screenshot of the WinForms application running on Linux, BSD, Mac OS, etc., and Dotgnu provides multiple DEMO and source code for developers, I have successfully compiled and running WinForms applications under Cygwin. program. However, since I can't successfully configure a complete DotgnU running environment under Linux, I can only run the WinForms program. But I believe this difficulty is only temporary, I will solve the problem as soon as possible and give you a WinForms version of HelloWorld. :)

At present, the Dotgnu project is still in progress, so we have reason to believe in dotgnu's work, believe that our .NET programs will have successfully run on different operating systems one day!

------------------------------

Musicland

http://blog.joycode.com/musicland

http://musicland.blogone.net

转载请注明原文地址:https://www.9cbs.com/read-22752.html

New Post(0)