Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run C# code on Linux server easily?

Tags:

c#

linux

I have a PHP website which I am learning PHP on, which is on Linux server. How can I run this C# code without conflicting with current PHP code? When I open URL like site.com/hello.cs, it just shows the whole thing as text? What do I need to run this code on server?

public class Hello1
{
   public static void Main()
   {
      System.Console.WriteLine("Hello, World!");
   }
}
like image 846
Gurnor Avatar asked Nov 04 '22 15:11

Gurnor


1 Answers

C# files (.cs) need to be compiled before they run. Check out the Mono project....

Here's the basic outline of what you need to do to get a web site running:

  1. Download MonoDevelop (the Mono analogue to MS Visual Studio) from the link above.
  2. Go to File > New > Solution
  3. Create an ASP.NET or MVC project from under C# at the left.
  4. Design your web site and deploy to your web server. (I realize this glosses over a lot, but post another question here when you hit a snag.)

Also, just so you know, your code example above won't render as a web page as is. That's code for a command-line-based application. MonoDevelop comes out of the box with decent templates for web sites though.

like image 89
FishBasketGordo Avatar answered Nov 09 '22 10:11

FishBasketGordo