I've got a relatively small ASP.NET project that was written using C# 4.0.
I was wondering if anybody had managed to port such a project over to running under a webserver on Linux, the latest information I can find appears to only have support for ASP.Net 2.0 - Configuring and running Mono ASP.NET 3.5 (AJAX.NET) on Linux computers
The project uses LINQ-to-SQL for the entire data access layer, and I know Mono itself support LINQ, so I thought it stands to reason that it should work.
I just want to know if it's a complete waste of time or not before starting.
Thanks.
I run an ASP.NET 4.0 application on Suse Linux using mono. My experience with mono is that it just works. My app is ~ 15.000 LOC and uses third party components like mongo-csharp-driver, lucene.net, elmah, munq, and sphorium.webdavserver.
I've had almost no compatibility problems during development - and the ones I had where easily worked out (for example sphorium accesses the registry; this obviously works different on Linux/Mono). I've even started developing with Visual Studio instaed of MonoDevelop and without the Mono plugin, because Visual Studio is a better IDE, and it just works when I compile my web app on linux and deploy it on Apache (even though I develop with .NET on Windows).
I've written a short blogpost on getting started with the setup
This is definitely not a waste of time. The company I work for converted our VB.Net application to C# so that it can run under mono. This application has over 200k lines of code. We now are running with Ubuntu/Apache/Mono/Postgresql on Amazon ec2.
The only concern I would have is with your database. If it is MS SQL then you will need to look at migrating to MySQL or Postgresql. Again we did this with 300+ tables and 900 stored procedures. It is definately something worthwhile in the long run.
I think that the best way to get started would be to setup a local environment running something like Ubuntu. You can get the near latest versions of mono from the repositories at http://badgerports.org/ or if you prefer you can the latest versions as build scripts which are maintained here. Install monodevelop and build your code on linux with mono. From experience the mono with C# is a pretty much a complete implementation of the .net framework. I would be surprised if there was something in your application that is yet to be implemented in mono.
I have an answer here showing an easy configuration for your application under apache. I use this configuration for mono applications running on Ubuntu.
Related
C# (or similar) Pros,
It's very possible that this post gets moved elsewhere as I have not posted before. I spent 2 years learning React, Next.js, Express, JavaScript, and PostgreSQL, and I have decided to refocus my efforts on really learning programming more deeply with a switch to C#, .Net, ReactJS, and possibly Blazor WASM later.
As I have been researching this for a while to determine if I was going to go the Java 17 route or C# 10+, I decided on .Net and C# with a goal of landing this type of role in the past. I like Java, too, but I decided C# seemed cleaner (to me).
My question is related to the development environment. I developed a website with the JS technologies using an Ubuntu 20.04 VM inside VMWare WS Pro, and I am not sure I want to go this same route. I want to learn to do some of the things I did not do before like setting up separate environments for development, staging, and production for websites.
I have been trying to determine how to set up the environment for C# and .Net using my existing Windows 11 laptop. I have plenty of power, and I would ideally like to code without VMs. Also, I'd like to be able to give VS a try instead of VS Code. Please also note that I am not married to Windows and would consider Mac since it has VS for Mac now.
I looked at Docker Desktop, Windows VDA licensing, and .Net 5 / 6 running simultaneously on the laptop. Mentally, I didn't fully understand most of those configurations.
I'm hoping there is something that I am missing in a better way to set this up to code C#, ReactJS, and MongoDB so that I don't mix too much with my personal PC settings and environment.
How would a professional C# developer set up using only their Windows laptop to keep the development environment(s) separate from the personal while using the same??
I appreciate any ideas offered.
James.
Nice first question. As a C# developer myself i will advise you to begin using Docker for your development. And if you dont want to use VS Code you can look at Visual Studio Community Edition. This is the free to use VS if you're using it for yourself, otherwise take a look at the usage part. An begin using Git (Github/Gitlab) to store your code.
And at this time i should suggest you to start developing in .net 6 as this is the latest LTS version of .net. Visual Studio is also capable of creating Dockerfiles for you that you can use for creating containers, if you use the right project type (Web).
In my opinion, It's very common to use a virtual machine or docker to separate the development environment from the personal environment on the same PC, But if you don't want to use them, I think you can create another user to login windows as your development environment, Their development environment is not shared (of course you can set them manually). In Asp.Net Core you can also set multiple environments. Refer to document.
I have years of experience developing on microsoft development stack primarily visual studio 2012/c#. But right now, im required to develop app on linux. While i know c++, its been years since i really touch that. I have few questions.
Can i develop using mono and compile binary for linux and windows with no code(or minimal) code changes?
Can i develop on windows platform using visual studio 2012, compile for linux on window platform? do i need to use virtual machine for compiling for linux in windows platform?
How do you setup your development environment if you want to develop linux app on windows platform(develop on windows, compile for linux and windows. my linux box use for testing is a separate machine.)
Some info on what im working on.
My project is about network channel analysis. The client is cheap industrial linux box most probably with no ui. Im using mono/c# to develop the client. The server would be windows develop using vs2012 c#. Most probably using wpf as ui. Im planning to share network/communication library between linux(client) and windows(server). My primary concern for using linux is for cost saving since the client is almost thousand units.
thank you.
Mono runs executables in PE (Portable Executable) format, the native file format of Windows. There's no need to "compile for Linux", as long as your app is pure MSIL. And even if you use native DLLs through p/invoke, Mono and Wine work together to run the Windows files on Linux.
(The a.out and ELF executable formats used by native Linux applications don't have mechanisms for storing .NET metadata, the PE format was modified to support .NET, so that's what .NET Framework (not Micro Framework) implementations use regardless of platform)
The most important things to consider at the beginning are,
WinForms of Mono is problematic. Not only most third party controls won't work properly, but also libgdiplus itself is not 100% compatible with Microsoft's GDI+. It might appear to be a sweet option, but later you might still need to fight hard against the incompatibilities.
WPF is not an option as Mono does not support it yet.
GTK# is your best choice for UI, which blends naturally with Linux distros. If you refactor your Windows project properly, you should be able to share the non-UI code between your Windows and Linux solutions. This is what Mono guys recommend (not only use native UI frameworks for Windows, Linux, but also for Mac/MonoMac, iOS/Xamarin.iOS, and Android/Xamarin.Android).
So go back to your questions,
You should never wish for no code change for a real world project. No, that's impossible. As I said earlier, you have a chance to share most non-UI portion.
You can develop the non-UI portion and the Windows only portion using VS2012 and test them out on Windows. If you plan to use Mono's WinForms or GTK#, you must develop and debug on Linux using MonoDevelop. Thus, you need either a virtual machine or physical machine of Linux.
For me, I frequently switch between Linux/MonoDevelop and Windows/VS.
As Mono + C# is much more productive than using C/C++, many successful Linux apps are developed on Mono, such as Banshee and Tomboy.
You can use Visual Studio without problems but for example you cannot use WPF, while Windows Forms are ok. For more information what you can use visit: http://www.mono-project.com/Compatibility
Moreover there exists Mono tools which integrates with VS: http://www.mono-project.com/GettingStartedWithMonoTools
I am creating a project on C#-.Net. The 'exe' file generated from the project is not executable on machines which do not have the .Net already installed. This error is popping up:
To run this application you first must install one of the following versions of the .NET.Framework: V4.0.30319
I don't want to make an installer file which installs the dependency files (.Net FW and other...) on PC.
As project requirement, I want to make an 'exe' that runs on every Windows PC without installing software or dependency sofware -> .Net FW. Just when clicked and the s/w exe should execute.
Is it possible to make such machine independent 'exe' for Windows from .Net ??
That's not exactly possible (there are some tools out there that will allow you to bundle dependencies, but I wouldn't recommend using them).
Your best possible approach to this is using an as-old-as-possible framework, for example .NET Framework 3.0. This way you'll use a framework version that is already preinstalled on pretty much all systems in use. Or in other words, you'll ensure your program runs on as many systems as possible out of the box. Just provide a link to the runtime in case someone is still missing it.
Also just to note that this is far better compared to what happened to the first few iterations of the .NET Framework: Those executables would just crash with a complex error message not telling the user that it's just the runtime missing. It improved a lot over time.
Also, just as an alternative: Have you thought about using ClickOnce deployment? This will allow you to provide users a simple and minimal installer they won't really see either. It will only download and install dependencies that are still missing. Also this is built into any edition of VisualStudio, even the Express ones.
This error is popping up
It is not an error. Just a friendly reminder to the user that your program need .NET 4 to be available before your program can run. He'll click "Yes, please!" and everything solves itself automagically.
You could create an installer to avoid the message. But, given that you don't want to do that, and it already takes care of it for you, there is very little point.
More about what this all looks like and why it works this way in this answer
"As project requirement, I want to make an 'exe' that runs on every Windows PC without installing software or dependency sofware -> .Net FW. Just when clicked and the s/w exe should execute.".
1) What if the version of Windows doesn't have any .Net Framework?
2) What if the version of Windows doesn't support any version of .Net Framework? (.Net didn't come around until Win2K/ME ish times, and Windows 95 won't take most .Net frameworks, 3.1 / 3.5 wont even take Mono)
"Is it possible to make such machine independent 'exe' for Windows from .Net ??"
Sounds like you're trying to make something like a Setup.exe that can be a single download that will work out the specifics after the fact... Actually the "machine independent" makes even C++ unsuitable, because while C++ will work on Windows, Mac, Linux, Unix, and a whole slew of more exotic systems with x86, x64, i64, PPC, ARM24/32/64 etc. (all of which exist with Windows installed on them, out there, in the wild, but are pretty rare) once the executable is compiled and linked, it will be targeted towards a single CPU architecture and OS. (OS/2, GEM and DOS all use .exe files, and there are some similarities between them, but most other OS don't require any specific file extension for executable binaries)
So, .Net isn't a terrible idea for this reason, any more than a .jar, .pl or .py would be. (which is relatively common for *nix software that you hope will run on Linux, Mac and BSD Unix... maybe even Solaris or HP/UX etc.) If you target MSIL, rather then x86 or x64, then your .exe will run on PPC Windows, DEC Alpha Windows, Itanium Windows, and ARM Windows, as well as the other two. (although this isn't what you are asking about) If you build it without a dependence on the WPF, or other Windows specific GUI engine, it will also work on Mac, Linux and BSD, so long as they have Mono installed. (it just may be worth considering, while you're at it... Versions of Windows Microsoft don't support with the appropriate .Net version will also need Mono to work this way)
To that end, I would recommend building a command-line executable in Mono, rather than .Net development environment. (Mono executable will run on .Net easier than .Net executables run on Mono... Though either is possible if you are careful about the dependencies you include in headers you import into your source)
I've had some success with this, writing a background service that would install on either Windows or Linux with the same binary executable. I used MonoDevelop. (https://www.monodevelop.com/) However, it's really just a flashy IDE around the core Mono development tools. (https://www.mono-project.com/)
Forgive me for asking a common question, but I couldn't quite get what I needed from what I found so far.
First question - SQLite. I am using this DB as in my C#.NET 3.5 windows service and it works great, I was looking for a portable solution, because I would like port my service to a linux daemon etc, using Mono, which seems to support it. However, I am not sure how to implement this. I had thought the dll was compatable, but it seems there is a seperate dll for Mono/.NET which I should have expected. Does this mean I need to seperately code/compile for each platform or is there something that would allow me use of SQLite with the same code on various platforms? I have encountered this a few times in my searches, csharp sqlite, a "reimplementation". To be honest, this is quite new to me, is it of use? The Mono SQlite page says that they Mono.Data.Sqlite code is based on System.Data.SQlite and goes on to say...
"We have chosen this way as means to
provide a migration path for
developers using SQLite in their .NET
applications"
Are they referring to creating a new, seperate binary? Or could I run my code as is with some adaptation?
Second question - GUI. As far as I can tell the two main options for cross platform dev in .NET would be GTK# and Winforms. Again however, its the specifics of implementation that are a bit hazey. Can I create a win forms GUI in visual studio as I normally would then easily migrate this using mono? Or should I develop this in something like X-Develop or MonoDevelop?
Many thanks for your advice/patience :D
To help out a little bit here I used the full mysql dll file that was provided and I was able to compile my program on windows using visual studio, and then deploy it to Linux without changing anything(except the case of the mysql dll file, which is kind of annoying you'll see what I mean at some point).
Also from what I've heard winforms isn't totally supported by mono yet, but I may be wrong. I haven't done a gui cross platform yet, but I would test winforms first, just so you could develop it in visual studio, and if that doesn't work I think GTK should be fine.
You just need to make sure that the dll's are compiled for .net 3.5 or below and you should be fine(90% of the time).
Check this out here, http://www.mono-project.com/MoMA and also the link that chris provided.
I'm looking into Mono and .NET C# and we'll be needing to run the code on Linux Servers in the future when the project is developed. At this point I've been looking at ASP.NET MVC and Mono.
I run an Ubuntu distro and want to do development for a web application, some of the other developers use Windows and run other .NET items with Visual Studio.
What does Mono not provide that Visual Studio does?
If running this on Linux later shouldn't we use MonoDevelop?
Are there some third party tools or add-ins that might be an issue with Mono later?
What does Mono not provide that Visual Studio does?
MonoDevelop is presumably what you mean here. MonoDevelop offers cross platform development on Linux, Mac OS X, Windows based on GTK. However it is not as polished as Visual Studio for obvious reasons - it's 3 people making it, not hundreds. It has some nice features, especially its source control plugin architecture. However as Visual Studio Express is free there aren't many advantages on Windows to using it.
It uses the same .csproj and .sln format as Visual Studio, however the XML docs format is different.
If running this on Linux later shouldn't we use MonoDevelop ?
As I mentioned above, the project formats are inter-operable.
Are there some third party tools or add-ins that might be an issue with Mono later?
Unlike Visual Studio, there aren't a huge wealth of add-ins for Monodevelop. The ones that you use in Monodevelop won't effect your .csproj files at all, as anything Visual Studio cannot read it generally ignores.
As people have said don't confuse Mono for MonoDevelop. MonoDevelop is an IDE for Mono that originally came from (forked) SharpDevelop.
Mono is the cross platform framework that 'apes' the Microsoft CLR and framework libraries.
I don't have much experience in this area but...
The Mono Project Roadmap has an overview of features that are new, upcoming, and not present in Mono compared to MS.NET. Even where Mono has the same classes as .NET, note that compatibility is not 100% (although that is generally their goal). I'm not sure if there exists a comprehensive list of things missing in Mono.
MonoDevelop is now available on both Windows and Linux so you're probably best off using it. However, MonoDevelop does appear to use the same project file format as Visual Studio and SharpDevelop, so you could make an attempt at mixing IDEs.
Of course, when using 3rd-party .NET libraries, note that many of them have not been tested with mono, and in particular anything that uses P/Invoke will not work on Mono for Linux. However, most incompatibilities with mono are minor, and if you stick with open-source libraries you can always fix any incompatibilities you run into.
You might also take a look at Mono Tools for Visual Studio. It lets your visual studio developers target and test with the mono platform.
You're aiming to always have support, and/or primarily use the software on Linux, correct? This is actually a question I asked the Mono developers at a conference a little while back, and it basically boiled down to what you want to do with it.
If you want it to always work on Linux, then use Mono. If you only care about Windows, then use Visual Studio.
If you're using Mono, then use MonoDevelop across all developers. It'll just make life a lot easier later on, and it'll make sure that whatever you write in the one will work for everyone.
Unfortunately, I do not know the answer to the exact limits/advantages of Mono vs. .NET, aside from .NET being further ahead, and Mono playing catch-up, nor about different addons.
If none of your developers need to develop on Mono for certain features, I suggest you all use Visual Studio on Windows. Then test the applications on Mono via
Mono Tools for Visual Studio
manually copy the binaries over
check out the code on Linux and build in MonoDevelop.
Personally I experienced a lot of small troubles when I tried out the third way, but luckily I am capable of finding workarounds.
It is only when you touch Mono, you know which part of your application needs to be tuned.
http://www.mono-project.com/Start
If you can help it, it'd recommend avoiding the Mono implementation of Remoting. There seem to be some unexpected hiccups and debugging it is not straight-forward.
We had a very Remoting heavy product that we tried to port to Mono so we could support Linux. Due to being unable to resolve the Remoting issues, we eventually had to abandon our attempts at supporting Linux altogether.
Caveat: my experiences may be outdated. See comments below
You don't need MonoDevelop in order to run ASP.NET program in Linux, make a shared folder on your development server (VMWare'd or real one), test often so you can easily work-around what's missing from Mono
That's the same approach I'm using in my .NET Remoting program I host on Ubuntu server. But I do the reverse, since I'm a solo programmer, I make a shared folder on my Windows development machine, then access that shared folder on my Ubuntu test server (vmware'd). On ASP.NET stuff, if the changes don't reflect on your Ubuntu test server, in Terminal just touch the Web.Config file in your Ubuntu test server. i.e. touch Web.Config, then refresh the page
Mono has a fully functional implementation of ASP.NET. This includes full support for ASP.NET Web Forms and Web Services. This essentially means that more or less any ASP.NET application that you have developed using with the .NET Framework will work with Mono. Obviously there might be changes needed, such as data access changes, removal of any
reliance on .NET Framework BCL types . Mono- Oracle users-.Net Programming C# : ubuntu 11.04