Sign in to follow this  
sunjester

[sunjester tuts] Using C# (.NET code/apps) on Linux

Recommended Posts

Introduction

All of my tutorials are written, tested, and meant to be used on Linux. I am using Ubuntu xenial (currently 16.04). You can use any debian distro and follow any of my tutorials. I will not pander to the Windows kiddies, don't ask.

 

Directions

First, let's check what version you have, you can use the lsb_release command.

 

lsb_release -a

 

18.04

sudo apt install gnupg ca-certificates
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb https://download.mono-project.com/repo/ubuntu stable-bionic main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list
sudo apt update

 

16.04

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
sudo apt install apt-transport-https ca-certificates
echo "deb https://download.mono-project.com/repo/ubuntu stable-xenial main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list
sudo apt update 

 

14.04

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
sudo apt install apt-transport-https ca-certificates
echo "deb https://download.mono-project.com/repo/ubuntu stable-trusty main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list
sudo apt update

 

Next, install Mono

sudo apt install mono-devel

Now we can compile and then run the C# code below, that i've saved in a file named hello.cs

using System;
 
public class HelloWorld
{
    static public void Main ()
    {
        Console.WriteLine ("Hello World");
    }
}

using the csc to compile

csc hello.cs

 

and using mono to run the .net executable

mono hello.exe

 

WinForms

You can compile the winforms applications using the following argument

-r:System.Windows.Forms.dll

Gtk# Forms

 

-pkg:gtk-sharp-2.0

Share this post


Link to post
Share on other sites

what is gtksharp

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this