Execute C# code in Linux

WBOY
Release: 2023-08-30 18:53:01
forward
1373 people have browsed it

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
Copy after login

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

root/kali:~/ sudo apt-get install mcs
Copy after login

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");
      }
   }      
}
Copy after login

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
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template