How to run C# project under Linux
You're looking for the Mono Project - a cross-platform (but primarily targeted at Linux) implementation of the .NET Framework and CLR. It's capable of running binaries compiled for the CLR (MS .NET), or of creating its own native Linux binaries.
The project has been going a while now, and it's current version (2.4) is very usable, even for production purposes. See the project roadmap for details of the main features and milestones of current and future releases.
Details about the current state:
The great majority of the BCL (Base Class Library) is available on Mono, with the exception of some of the .NET 3.0/3.5 stuff, such as WPF (which has minimal support currently) and WCF (almost non-existent support). Silverlight 2.0 is however being supported via the Moonlight project, and progress on that is going well. WinForms functionality (which uses GTK# as a backend) is however quite complete, as far as I know.
Implementation of the C# 3.0 language is effectively complete, including the C# 3.0 features such as lambda expressions, LINQ, and automatic properties. I believe the C# compiler is mature to the point that its efficiency is at least comparable with that of the MS compiler, though not yet matching it in some respects. What's quite cool (and unique) about the Mono C# compiler is that is now offers a compiler service - in other words true dynamic compilation from code (without using the CodeDOM). This is something that MS will perhaps only add in .NET 5.0.
Run Microsoft Visual Studio C# project in Linux
Many step are required in order to run this project.
First delete global.json
file and then run dotnet migrate
and remove the backup directory.
(Optional) In some case you will need to clean the solution. If DotNetWallet.xproj
and project.json
are still there, remove it and run the twxo following command.
dotnet sln remove src/DotNetWallet/DotNetWallet.xsproj
dotnet sln add src/DotNetWallet/DotNetWallet.csproj
Then, remove the first line (using DotNetWallet.KeyManagement;
) from FakeData.cs
file. This is an unused using statment. there are no impact to remove it.
Now, you can run dotnet restore
, dotnet build
then dotnet test
.
Run c# visual studio project in windows, created in ubuntu
The easiest solution: create new, empty console app and paste content (.cs) files from linux repo to it. Build and compile.
Remember to resolve conflicts which may occur (libs used in linux environment may be problematic in windows).
Run C# code on linux terminal
Of course it can be done and the process is extremely simple.
Here I am explaining the steps for Ubuntu Linux.
Open terminal:
Ctrl + Alt + T
Type
gedit hello.cs
In the gedit
window that opens paste the following example code:
using System;
class HelloWorld {
static void Main() {
Console.WriteLine("Hello World!");
}
}
Save and close gedit.
Back in terminal type:
sudo apt update
sudo apt install mono-complete
mcs -out:hello.exe hello.cs
mono hello.exe
Output:
Hello World!
Can any c# application be run on linux
Update for 2020
.NET Core and .NET Framework are being merged together into ".NET 5". For all intents and purposes, this is just the next version of .NET Core (and .NET Framework is going away).
WPF still only runs on windows (though a universal XAML based UI system is in development), even though its running on .NET Core/5, and you still have to build specifically for Linux for supported project types, but the cross platform support is much better than when I originally wrote this.
Original
For .NET code to be able to run on Linux, you need a version of .NET that is compatible with that platform.
Full .NET is windows-only, but there is the Mono framework which runs on Linux. .NET Core is also being ported to linux.
Neither Mono or .NET Core supports the entirety of standard .NET. For example, neither will let you run a WPF application. So as long as your code is compatible with one of the aforementioned frameworks; yes, you can run it on Linux.
For your specific example, the classes you mention should be supported, and I don't think you'll have any trouble running under either Mono or .NET Core.
How to I run a file on ubuntu which i compiled with Visual Studio on Windows for Linux
You could flag your file as executable:
cd you_vs_code_foler/bin/Release/net6.0/publish/linux-x64
chmod +x your_programm
./your_programm
If you need to install .NET runtime at Ubuntu: try this:
sudo apt-get install -y dotnet-runtime-6.0
For further information and for other distrubtions please consult:
https://docs.microsoft.com/en-us/dotnet/core/install/linux
How can I compile C# code on Linux terminal?
to compile a C# file, you need to have dotnet installed, here is a link with the info on how to install it. Dotnet
Then you go to where the file is and put dotnet run without <>
Although it is highly recommended that you create a project first and paste your code into the Program.cs file. This way you will avoid unnecessary headaches.
Related Topics
Change a Web.Config Programmatically with C# (.Net)
The Cast to Value Type 'Int32' Failed Because the Materialized Value Is Null
Detecting Design Mode from a Control's Constructor
Javascriptserializer.Deserialize - How to Change Field Names
Hide Console Window from Process.Start C#
How Do Foreach Loops Work in C#
Convert Integers to Written Numbers
Detailed Explanation of Variable Capture in Closures
ASP.NET MVC Binding to a Dictionary
How to Close a Login Form and Show the Main Form Without My Application Closing
Lifetime of ASP.NET Static Variable
Is Double Multiplication Broken in .Net
Using Stored Procedure Output Parameters in C#
How to Create a Dynamic Button Click Event on a Dynamic Button
How to Set Processor Affinity to a Thread or a Task in .Net
How to Merge Datagridview Cell in Winforms