16

TL;DR : what are the options nowadays to run a VS2015 solution on Linux?


I have a .NET application that runs fine in Windows and have received requests to port it to Linux. I have been trying very hard to understand what it meant today in 2015 but I am really confused with all the old posts pointing to Mono and the new posts talking about vNext (and still mention Mono). Also I have an okay background with .NET but I don't know a lot about Linux in general...

I followed a recent tutorial and managed to compile and run a Hello World console app in Linux. That required some installation of stuff I don't know, including Mono, and then running some "k" commands (kpm restore, kpm build, k run). However now I don't know how to move on to my real-world case scenario.

I have a VS2015 solution which has a lot of projects but only 4 are worth mentioning here: - CommonStuff - ServiceCore - ServiceWindows / ServiceConsole

All the code is in the ServiceCore project (class library), which itself has a reference to CommonStuff (another class library). ServiceWindows is a Windows Service project that simply calls the Main function of ServiceCore, and ServiceConsole does the same thing but in a console app (for debugging reasons, since it's not possible to debug a Windows Service project from Visual Studio).

Both CommonStuff and ServiceCore include a lot of .NET libraries as well as some 3rd party dlls. No Windows specific code however, no pinvoke or funky stuff.

If we consider ServiceConsole to become the app I want to run on Linux - what do I need to do to make it happen? Compiling Hello World was one thing but now, with all thoese references... I don't know where to start. Also, I can't even have the code to be compiled in Linux (proprietary code) so I need the code to be compiled in Windows and the compiled dll/exe to be run directly in Linux - is that something that is possible? I have seen a few posts saying that Mono can run compiled applications, but each and every Mono turorial I have seen starts with compiling. Also I'm not sure what this vNext is. I read stuff about the ability to run code in Linux if it's targetted for .net 6... but I have no idea how or what it means.

I would greatly appreciate if somebody could take some time to explain in some details what the options are nowadays and if it's realistic for a professional application or if it's only good for Hello Worlds yet.

Thanks

EDIT: Ok so it seems I can compile my code in VS and somehow run it on Linux using Mono - how?

Nicolas
  • 403
  • 1
  • 6
  • 18
  • 1
    _"Windows Service [...] nothing Windows-specific"_ does not compute. See [How to migrate a .NET Windows Service application to Linux using mono?](http://stackoverflow.com/questions/637948/how-to-migrate-a-net-windows-service-application-to-linux-using-mono). vNext or ASP.NET 5 is the next thing for web applications, so not relevant to your situation. I can't help you further than that, I haven't tried to run .NET on Mono beyond "Hello, World!" as well. – CodeCaster Sep 18 '15 at 15:47
  • I code .Net/Mono service oriented applications on OS-X and deploy the resulting CILs to Windows and Linux platform all the time... This question is so general that it can not be directly answered. Is Mono a viable CLR platform to run xplat applications, yes... Beyond 'Hello World', yes, Professional apps? yes, of course, etc.. The real answers will be based on your application, your code,, user experience required, platform requirements, etc... You stated you are not using non-managed InterOp, but what Windows specific code, if any, is your Service using, etc... – SushiHangover Sep 18 '15 at 16:00
  • I don't think it matters that much that it is a Windows service. It is just some code that I run as a Windows service, but as I said, it could be run as a console application. To be more specific, the purpose of the application is to idling wait for requests (received via SignalR, so websockets or long polling) and then connect to some database (for example mysql, managed by 3rd party dlls) to finally send the data to a webservice of ours. The only thing Windows-specific is writing to Windows logs but I can replace that easily with writing to some file for Linux. – Nicolas Sep 19 '15 at 16:35
  • So if I understand correctly I should not be looking at the "new" MS cross-platform technology (e.g. vNext) because it's web only. And therefore I should rely on mono which has been out for quite some time now. – Nicolas Sep 19 '15 at 16:36
  • Possible duplicate of [How to run .net application on Linux environment?](http://stackoverflow.com/questions/887193/how-to-run-net-application-on-linux-environment) – jww Dec 27 '16 at 16:47

1 Answers1

16

I often develop multiplatform or linux-only complex applications, using Visual Studio 2015 on windows. You can just compile it in VS, copy to linux and run - almost always this will just work. If you do serious development you may want to compile under mono to spot some missing methods \ different signatures, but that is not required.

Now, windows service can be changed to just console application. Basically it is just console application which is managed by external tool. On linux there are different tools which allows you to manage (start \ stop \ restart on failure and so on) your "service" applications.

For web applications I usually use ServiceStack, which runs on mono without problems. You can even self-host it again as console application, behind nginx. You can also host asp.net applications under apache\nginx, with little or no code changes.

Half an year ago I "ported" big project which was developed for 2 years from windows server to CentOS 7 server, mostly by just copying stuff to centos and running (with very little changes, without recompilation under mono). Of course that project had many third party dependencies, and some developers of those dependencies did not even know mono exists. Nevertheless they just worked. And that solution had about 90 VS projects.

Of course, not every complex project is so easy to port, especially if you use native libraries often, but usually that is not the case. Also, if you work with sql server, note that sql server driver in mono is quite bad from my experience. I use postgre and avoid sql server with mono if I have a choice. Working with images in mono is also not very good, buggy and unstable. I avoid using Bitmap class there at all costs and pinvoke into imagemagick C api instead. But you need to do there only if you do serious and extensive imaging, for basic tasks it's fine.

Long story short - running a .NET app in Linux in 2015 is not a problem nowadays.

Update. If you are in 2018 already - there is almost no reason to use mono on linux, besides specific cases like mobile application development with Xamarin, game development with Unity, or UI application. If you just need regular console\service application (including web server) - use .NET Core. It's already stable and fast enough for production use, and from my experience - already much less buggy than mono even been. Porting your full .NET\mono application to .NET Core is in most cases relatively straightforward, though certain libraries might not yet be available on new platform. But if you are starting new project - choose .NET Core no doubt.

Evk
  • 98,527
  • 8
  • 141
  • 191
  • "You can just compile it in VS, copy to linux and run" - I can compile in VS and copy to linux - but how exactly do I run? What command do I need to run? Can you give more details? – Nicolas Sep 19 '15 at 16:32
  • Just install Mono. I'm not really sure what your problem is? – user9993 Sep 19 '15 at 16:45
  • @Nicolas, Install mono, then do "mono YourConsoleApp.exe". If you want to run under service manager, just read how to run any apps under it (not related to mono). – Evk Sep 19 '15 at 16:49
  • When I run "mono MyApp.exe", I immediately get an exception: "Could not load file or assembly 'Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral' or one of its dependencies.". Please don't tell me mono only works with c# compiled projects ;) Also does it matter if built in Debug or Release? – Nicolas Sep 19 '15 at 17:06
  • 2
    @Nicolas well I never used VisualBasic, so not much to say about this... But you may want to read docs - http://www.mono-project.com/docs/about-mono/languages/visualbasic/ – Evk Sep 20 '15 at 18:03
  • the inference I draw is that `.NET` languages, like visualbasic, compile to the `dotnet` runtime which Linux uses. So the language is immaterial. Unless you step outside what `dotnet` has -- so nothing platform specific. Microsoft. – Thufir Feb 17 '18 at 17:54