Home  >  Article  >  Backend Development  >  Execute C# code in Linux

Execute C# code in Linux

WBOY
WBOYforward
2023-08-30 18:53:011308browse

So far, .NET-centric applications have been targeted at the Windows operating system, but now Microsoft has introduced a new cross-platform application called Mono that can execute on Applications developed under .NET

Mono

Mono is an open source utility that allows developers to execute .NET-centric applications on other platforms such as Mac or Linux because It provides an installation package for the Windows platform, which can compile and execute .NET assemblies on Windows operating systems without installing Visual Studio IDE or .NET Framework SDK. Therefore, we can build live, production-ready assemblies using Windows Forms, LINQ, XML Web Services, ADO.NET, and ASP.NET by leveraging the existing core CLR namespace under Mono. First, use the wget utility to download the Mono binary and execute this series of commands to configure it correctly:

wget --no-check-certificate https://raw.github.com/nathanb/iws- snippets/master/mono-install-scripts/ubuntu/install_mono-3.0.sh
chmod 755 install_mono-3.0.sh
./install_mono-3.0.sh

Alternatively, you can install the MCS package and compile the .NET binary as shown below ;

root/kali:~/ sudo apt-get install mcs

C# Code Compilation

The infrastructure of a Mono console application is almost similar to a traditional C#.NET console application. To develop your first Mono-based console application (test.cs), open any code editor (such as VIM) and type the following code.

using System;
namespace test {
   class test{
      public static void Main(string[] args) {
         System.Console.WriteLine("C# app Compiled on Kali Linux");
      }
   }      
}

Then, open a terminal and enter the following commands to compile the code.

root/kali:~/ mcs test.cs
root/kali:~/ ls
test.cs test.exe

The above command will generate an executable file like windows.exe. Now hit the ./test.exe or mono test.exe command to run the C# binary; here, the screenshot summarizes everything we have done so far.

在 Linux 中执行 C# 代码

The above is the detailed content of Execute C# code in Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete