Need to run C# on linux server - c#

I used to be able to run vb.net apps using just this
apt-get install mono-runtime
apt-get install mono-vbnc
But I now need at least 2.8.0 to run a certain app that has already been compiled on windows. I have the option between the following OS's
ubuntu-12.04-x86
ubuntu-12.04-x86_64
ubuntu-12.10-x86
ubuntu-12.10-x86_64
centos-5-x86
centos-5-x86_64
centos-5-elastix_2.0.1_amd64
centos-6-x86
centos-6-x86_64
debian-6.0-x86
debian-6.0-i386-minimal
debian-6.0-x86_64
debian-6.0-amd64-minimal
debian-7-x86
debian-7.0-x86_64
I've tried the following on multiple versions of ubuntu.
#!/bin/bash
echo Checking for prerequisites. Please enter password if prompted.
sudo apt-get update
sudo apt-get install libpng3 libpng3-dev libtool libtiff4 libtiff4-dev libexif12 libexif-dev libgif4 libgif-dev libpango1.0-dev libatk1.0-dev bison automake autoconf make gcc gtk-sharp2 build-essential xorg-dev libfreetype6 libfontconfig libfontconfig-dev gettext libglib2.0-dev git mono-complete libjpeg-dev
echo Downloading latest build of mono...
git clone git://github.com/mono/mono.git
echo Navigating to mono install directory.
cd mono
echo Building mono from source...
./autogen.sh --prefix=/usr/local
make
echo Installing mono, running with sudo
sudo make install
echo Done!
Checking the mono version says it has worked, but I cant actually run the app due to this error:
The assembly mscorlib.dll was not found or could not be loaded. It should have been installed in the 'usr/lib/mono/4.5/mscorlib.dll'.
Which OS should I use and how can I install mono 2.8.0 or later to run a C# app which has been compiled on windows?

Build a clean Linux OS from ISO, such as Ubuntu 12.04.
Install the stable Mono release on it, such as apt-get install mono-complete. This is required to bootstrap the later steps.
Install Git and check out Mono source code, and switch to a stable branch (such as mono-3.2.8-branch).
Build that version of Mono from source and install it.
I don't recommend 3.4.0 or 3.6.0 branch at this moment, as new commits are still added to them in the past week (June 17 today). 3.2.8 is also the Mono version bundled in Ubuntu 14.04.
What you have been wrong is to check out the master branch. No no, that's not a stable release you should use.

Related

How to install .NET Core on aarch64 architecture Debian

I'm new to Linux and want to code some C# on Linux for school. The problem is I don't know how to install C#. I already read the instructions from Microsoft, but I couldn't get it to work.
'arm64' is the Debian port name for the 64-bit Armv8 architecture, referred to as 'aarch64' in upstream toolchains. The snapd daemon and tooling that enables snap packages is available for arm64 architecture in Debian.
To install snapd:
sudo apt update
sudo apt install snapd
Either log out and back in again or restart your system to ensure that snap's paths are updated correctly. After this install the core snap in order to get the latest snapd:
sudo snap install core
C# is open source and cross platform now that Microsoft has released a version of .NET Core. To install .NET Core in Debian open the terminal and type:
sudo snap install dotnet-sdk --classic
sudo snap alias dotnet-sdk.dotnet dotnet # to run dotnet-sdk type dotnet
The instructions from Microsoft seem to assume that you are running Visual Studio Code on Windows, so they frequently don't work at all on Linux. The following instructions were tested on a Debian-based system (Ubuntu 20.04). I ran a few C# console apps for test purposes, but let's start with a simple one-line C# console app. Run these commands to build and run an example C# Hello World console app from the terminal:
cd ~
mkdir C#_Projects
cd C#_Projects
mkdir HelloWorld
cd HelloWorld
dotnet new console
dotnet build --output ./build_output
dotnet ./build_output/HelloWorld.dll
Results of dotnet ./build_output/HelloWorld.dll
Hello, World!

Adding an assembly reference in Visual Studio Code

I'm just working on a web project in VS code. I'm used to using the full blown IDE, but I'm developing for Linux, so I'm trying to see if I can accomplish the same things in VS code.
Basically it's gotten to a point where I need to add System.Web so I can use stuff from there, but I'm struggling to find how to do it. Usually I'd just right click the solution and go Add assembly reference, and all the .NET assemblies would be there.
I've found this answer, and I've added "System.Web.Http.Common": "4.0.20126.16343" to my project.json file. I can't find the dnu restore command though. I've read that it's deprecated, but can't find solid info on how to either install it or use its replacement if so. Is anyone able to help me?
EDIT: Sorry, I should mention I'm using Mono.
dnu-restore is now dotnet-restore. You can find the help here
And if you're still using the rc1.0 version the details on dnu-restore is https://github.com/aspnet/Home/wiki/DNX-Utility.
If you are on Windows right now:
In case .net core is not installed in your machine follow the guidelines here
To have the CLI's anyway, you'd need .net core SDK which can be found here
Open VS2015 Developer command prompt or your command prompt in administrator mode (preferably)
To create a new app: dotnet new
To run an existing app: dotnet restore and then dotnet run
If you are on an Ubuntu right now:
To add the package source for Ubuntu 14.04:
sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ xenial main" > /etc/apt/sources.list.d/dotnetdev.list'
sudo apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893
sudo apt-get update
And for Ubuntu 16.04:
sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ xenial main" > /etc/apt/sources.list.d/dotnetdev.list'
sudo apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893
sudo apt-get update
Then you can install it using:
sudo apt-get install dotnet-dev-1.0.0-preview2-003121
The new .NET Core SDK restore command is dotnet restore
To install the latest .NET Core SDK (Preview 2 version) and add any asssembly reference in Visual Studio Code, please refer to my post at How to add System.Data and System.Timers assembly references in Visual Studio Code 1.8?

Mono TypeLoadException on XmlPreloadedResolver

I'm working on porting a Windows console app over to Linux using Mono. On my dev machine (Ubuntu), the app works like a charm, but when I try it on my test machine (a vanilla Ubuntu 14.04 desktop install) I get the following error:
Unhandled Exception:
System.TypeLoadException: Could not load type 'System.Xml.Resolvers.XmlPreloadedResolver' from assembly 'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
The only thing I've done to "prep" the test machine is run sudo apt-get install mono-complete and sudo apt-get upgrade. When I run dpkg --list | grep mono-system-xml on the test machine I see this:
$ dpkg --list | grep mono-system-xml
ii libmono-system-xml-linq4.0-cil 3.2.8+dfsg-4ubuntu1.1 all Mono System.Xml.Linq library (for CLI 4.0)
ii libmono-system-xml-serialization4.0-cil 3.2.8+dfsg-4ubuntu1.1 all Mono System.Xml.Serialization library (for CLI 4.0)
ii libmono-system-xml4.0-cil
whereas on my dev machine I see this:
$ dpkg --list | grep mono-system-xml
ii libmono-system-xml-linq4.0-cil 4.2.1.102-0xamarin1 all Mono System.Xml.Linq library (for CLI 4.0)
ii libmono-system-xml-serialization4.0-cil 4.2.1.102-0xamarin1 all Mono System.Xml.Serialization library (for CLI 4.0)
ii libmono-system-xml4.0-cil 4.2.1.102-0xamarin1 all Mono System.Xml library (for CLI 4.0)
I don't know for sure that that version mismatch is the root problem, but it's all I've got to go on for now. I tried installing monodevelop on the test machine via sudo apt-get install monodevelop, and I tried upgrading from the xamarin servers by running
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
sudo apt-get update
to no avail. Is there a way to tell where that 4.2.1 version on my dev machine came from? And assuming that's the difference, why would this module be broken in the standard distribution? From the mono docs it's been implemented and stable for a long time...
So, it turned out this was basically just an order of operations problem.
I had installed mono-complete before adding the Xamarin feed, so I got the old broken 3.8 version of Mono that shipped with Ubuntu 14 instead of the latest and greatest. For whatever reason, adding the feed afterwards and doing an apt-get upgrade doesn't pick up the updated versions, so you either have to start clean and do things in the right order, or add the feed, look at the output from apt-cache showpkg mono-complete to determine the version you really want, and then specify it like sudo apt-get install mono-complete=4.2.2.30-0xamarin2.

Unreal Engine 4 Setup problems

I am trying to run the Unreal Engine-4 setup on Ubuntu 14.04 but when running the command
sudo apt-get install build-essential mono-gmcs mono-xbuild mono-dmcs libmono-corlib4.0-cil libmono-system-data-datasetextensions4.0-cil libmono-system-web-extensions4.0-cil libmono-system-management4.0-cil libmono-system-xml-linq4.0-cil cmake dos2unix clang-3.5 libfreetype6-dev libgtk-3-dev libmono-microsoft-build-tasks-v4.0-4.0-cil xdg-user-dirs
I am running into an error saying
The following packages have unmet dependencies:
mono-gmcs : Depends: mono-mcs (= 3.12.1-0xamarin1) but 4.0.2.5-0xamarin1 is to be installed
E: Unable to correct problems, you have held broken packages.
Any clues on how to proceed?
but 4.0.2.5-0xamarin1 is to be installed
It appears you are using Mono 3.x install instructions for Unreal Engine-4's setup.
In Mono 4.x, the gmcs compiler (a shell script to docs/mcs) has been dropped as support for only 4.x+ frameworks are supplied by the default installer.
Remove the "mono-gmcs" from your apt-get install list, and try again. I am not sure if anything is in Unreal 4 is dependent on a Mono 3.x install or if Mono 4.x will work...
You can alway pin your Mono version to 3.12.1. Remove:
deb http://download.mono-project.com/repo/debian wheezy main
from "/etc/apt/sources.list.d/mono-xamarin.list" and add:
deb http://download.mono-project.com/repo/debian wheezy/snapshots/3.12.0 main"
deb http://download.mono-project.com/repo/debian wheezy-libtiff-compat main"
Then you can:
sudo apt-get update
After that, try your Unreal Engine-4 setup routine again and the Mono version will match the setup steps on Unreal's web site.

How to run .NET 4.5 on XSP using Mono?

I have installed Mono 3 however when I run xsp or xsp4 it shows that I'm using .NET 4.0. I need to have .NET 4.5. Is it possible? Where can I configure it?
I've seen this page but I don't have any of those folders where I downloaded sources.
This is what it shows when I enter website by running xsp4:
Version Information: 3.2.7 (master/1eef047 C nov 28 18:16:30 EET 2013); ASP.NET Version: 4.0.30319.17020
How I installed Mono and XSP
Firstly I downloaded Lubuntu 13.10 32bit and launched it inside VirtualBox. Then did apt-get update and apt-get upgrade. After that rebooted the system.
Make sure all commands are executed as super user.
sudo -s
Got dependencies
apt-get install autoconf automake libtool g++ gettext libglib2.0-dev libpng12-dev libfontconfig1-dev mono-gmcs git
Downloaded sources of Mono and XSP
cd /opt
git clone git://github.com/mono/mono.git
git clone git://github.com/mono/xsp.git
Installed latest stable Mono from github
cd /opt/mono
./autogen.sh --prefix=/usr
make
make install
Installed latest stable XSP from github
cd /opt/xsp
./autogen.sh --prefix=/usr
make
make install
Tested that I have 4.0 running on XSP instead of 4.5
cd /home/pc/web
xsp4 # 4.0
xsp2 # 2.0
xsp # 2.0
My configuration
/usr/bin/xsp4 looks like it should use 4.5. Just like this answer suggested. Also, I don't have xsp4.exe in my /usr/lib/mono/4.0/ only in /usr/lib/mono/4.5/ so I cannot copy anything like suggested in that answer.
#!/bin/sh
exec /usr/bin/mono $MONO_OPTIONS "/usr/lib/mono/4.5/xsp4.exe" "$#"
You say "I don't have any of those folders where I downloaded sources" referring to /opt/mono/bin/xsp4. But you're confusing things, and I know it because you shared how you installed mono.
/opt/mono should not be the place where you clone the mono repository to compile it. You should clone it somewhere else like your home folder. I.e.: /home/username/code/mono.
/opt/mono is where usually people install a custom version of mono. The way they do it is passing this path to the --prefix argument. But you're passing /usr as the prefix argument! So then you're installing it to a different location compared to the SO answer that you point out.
Also, it is not recommended that you do ALL those operations as a superuser. You normally compile code without root privileges, and you only need sudo for the install phase. So don't do "sudo -s" before everything. Just compile, and when you're done, do sudo make install. This will also make you have binaries that are not owned by root.

Categories

Resources