Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

Running a Windows .NET application on Linux

3.00/5 (1 vote)
12 Mar 2013CPOL1 min read 38.3K  
Running the same compiled assembly on Windows and Linux.

Introduction

Today Mono contains the core development libraries, the development and deployment tools. Most of these are command-line tools and compiler, there is no complete replacement for Visual Studio to do Windows.Forms and ASP.NET applications natively on Linux. 

You can continue to use Visual Studio to develop your applications on Windows, the binaries produced by Visual Studio are binary compatible with Mono, so you only need to get these files to your Linux/Unix server. 

The same compiled assembly will run on Windows and Linux. You can test this by compiling it on Windows, copying the assembly to a Linux machine and running the mono applicationname.exe command there or you can create a batch file.

If you create a batch file, put a check on "Allow executing file as program" in the properties->Permissions: Execute and write the follow code inside the batch file:   

Bash
#!/bin/sh
exec mono applicationname.exe 

To run the program click twice in the file or in the command type the name of the batch follow by enter, next click Run. 

If the program is inside a folder type the follow code inside the batch file:

Bash
#!/bin/sh
exec mono "./folder name/applicationname.exe" "$@" 

Note: On Windows, the directory path separator is "\" while on Linux it is "/", it is possible to create files that contain a "\" in their names on Linux. 

For more information about portability please check this link: Mono Application Portability.

Note: MonoDevelop is an IDE primarily designed for C# and other .NET languages.

Note: Works in Windows (with .NET Framework installed, except the batch file) and Linux (with Mono installed). 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)