C# in Linux Environment

C# in linux environment

Learn Mono.

The Mono Project is an open
development initiative sponsored by
Novell to develop an open source, UNIX
version of the Microsoft .NET
development platform. Its objective is
to enable UNIX developers to build and
deploy cross-platform .NET
Applications. The project implements
various technologies developed by
Microsoft that have now been submitted
to the ECMA for standardization.

You can use the MonoDevelop IDE.

MonoDevelop is a free GNOME IDE
primarily designed for C# and other
.NET languages.

Developing C# on Linux

MonoDevelop, the IDE associated with Mono Project should be enough for C# development on Linux. Now I don't know any good profilers and other tools for C# development on Linux. But then again mind you, that C# is a language more native to windows. You are better developing C# apps for windows than for linux.

EDIT: When you download MonoDevelop from the Ubuntu Software Center, it will contain pretty much everything you need to get started right away (Compiler, Runtime Environment, IDE). If you would like more information, see the following links:

  • http://monodevelop.com/
  • http://en.wikipedia.org/wiki/MonoDevelop
  • http://en.wikipedia.org/wiki/Mono_%28software%29
  • http://www.mono-project.com/Development_Environments

IDE's for C# development on Linux?

MonoDevelop 2.0 has been released, it now has a decent GUI Debugger, code completion, Intellisense C# 3.0 support (including linq), and a decent GTK# Visual Designer.

In short, since the 2.0 release I have started using Mono Develop again and am very happy with it so far.

Check out the MonoDevelop website for more info.

How to check the OS version at runtime, e.g. on Windows or Linux, without using a conditional compilation statement

[Editor's Note: This answer was applicable before .NET 4.7.1, or before the Windows Compatibility Pack for .NET Core was released. The current best answer is Alex Sanséau's to Stack Overflow question How to check the OS version at runtime, e.g. on Windows or Linux, without using a conditional compilation statement.]

You can detect the execution platform using System.Environment.OSVersion.Platform:

public static bool IsLinux
{
get
{
int p = (int) Environment.OSVersion.Platform;
return (p == 4) || (p == 6) || (p == 128);
}
}

From the Mono FAQ:

How to detect the execution platform

The execution platform can be detected by using the System.Environment.OSVersion.Platform value. However correctly detecting Unix platforms, in every cases, requires a little more work. The first versions of the framework (1.0 and 1.1) didn't include any PlatformID value for Unix, so Mono used the value 128. The newer framework 2.0 added Unix to the PlatformID enum but, sadly, with a different value: 4 and newer versions of .NET distinguished between Unix and macOS, introducing yet another value 6 for macOS.

This means that in order to detect properly code running on Unix platforms you must check the three values (4, 6 and 128). This ensure that the detection code will work as expected when executed on Mono CLR 1.x runtime and with both Mono and Microsoft CLR 2.x runtimes.

which platform for porting C# application to Linux?

Simple: use C# and
Mono.

Mono is a port of the .Net Framework and works great under Linux.
I tested it on a Raspberry with Debian.

Running .NET Core API Linux Environment Launch Profiles

So, after some more poking around. It seems that you have to set the environment variable on the server, I had mistakenly thought this was some kind of "runtime environment" variable, nope it's a full on OS level environment variable:

LINUX

export ASPNETCORE_ENVIRONMENT=Staging

POWERSHELL

$Env:ASPNETCORE_ENVIRONMENT="Staging"

WINDOWS

set ASPNETCORE_ENVIRONMENT=Staging



Related Topics



Leave a reply



Submit