Click here to Skip to main content
15,885,014 members
Articles / Programming Languages / C#
Tip/Trick

Running a Windows .NET application on Linux

Rate me:
Please Sign up or sign in to vote.
3.00/5 (1 vote)
12 Mar 2013CPOL1 min read 37.7K   21   2
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)


Written By
Engineer
Portugal Portugal
My name is Nelson Souto, I develop software for fun and profit since 1992.

Comments and Discussions

 
GeneralMy vote of 3 Pin
Prasad Khandekar13-Mar-13 20:08
professionalPrasad Khandekar13-Mar-13 20:08 
AnswerRe: My vote of 3 Pin
Nelson Kosta Souto13-Mar-13 23:20
professionalNelson Kosta Souto13-Mar-13 23:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.