在2015年在Linux中运行.NET应用 [英] Running a .NET app in Linux in 2015

查看:62
本文介绍了在2015年在Linux中运行.NET应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL; DR:如今在Linux上运行VS2015解决方案有哪些选择?

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

我有一个.NET应用程序,该应用程序在Windows上可以正常运行,并且已收到将其移植到Linux的请求.我一直在努力理解2015年今天的含义,但我确实对所有指向Mono的旧帖子和谈论vNext的新帖子感到困惑(仍然提及Mono).另外,我对.NET的背景还不错,但是总体上我对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...

我遵循了最近的教程,并设法在Linux中编译和运行Hello World控制台应用程序.这需要安装一些我不知道的东西,包括Mono,然后运行一些"k"命令(kpm restore,kpm build,k run).但是,现在我不知道如何继续进行我的实际案例.

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.

我有一个VS2015解决方案,其中有很多项目,但这里只有4个值得一提: -普通的东西 -服务核心 -ServiceWindows/ServiceConsole

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

所有代码都在ServiceCore项目(类库)中,该项目本身具有对CommonStuff(另一个类库)的引用. ServiceWindows是一个Windows Service项目,仅调用ServiceCore的Main函数,而ServiceConsole则在控制台应用程序中执行相同的操作(出于调试的原因,因为无法从Visual Studio调试Windows Service项目).

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).

CommonStuff和ServiceCore都包含许多.NET库以及一些第三方dll.但是,没有Windows专用代码,没有pinvoke或时髦的东西.

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.

如果我们认为ServiceConsole成为我想在Linux上运行的应用程序-我需要做些什么才能使其实现?编译Hello World是一回事,但现在有了所有这些参考文献……我不知道从哪里开始.另外,我什至无法在Linux上编译代码(专有代码),因此我需要在Windows上编译代码,并且需要在Linux上直接运行已编译的dll/exe-这是否可行?我看到一些帖子说Mono可以运行已编译的应用程序,但是我见过的每一个Mono turorial都从编译开始.我也不知道这个vNext是什么.我读了一些有关在Linux中运行代码的信息(如果针对.net 6的话……),但我不知道它的含义或含义.

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.

如果有人可以花一些时间详细解释当今的选择,以及对于专业应用程序来说是否可行,或者仅对Hello Worlds有用,我将不胜感激.

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.

谢谢

好的,这样看来我可以在VS中编译我的代码,并以某种方式在Linux上使用Mono运行它-怎么做?

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

推荐答案

我经常在Windows上使用Visual Studio 2015开发多平台或仅限Linux的复杂应用程序.您可以在VS中进行编译,复制到linux并运行-几乎总是可以正常工作.如果您进行了认真的开发,您可能会想要 在mono下进行编译以发现一些缺少的方法\不同的签名,但这不是必需的.

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.

现在,可以将Windows服务更改为仅控制台应用程序.基本上,它只是由外部工具管理的控制台应用程序.在linux上,有许多不同的工具可让您管理(启动\停止\失败后重启等)

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.

对于Web应用程序,我通常使用ServiceStack,它可以在Mono上运行而不会出现问题.您甚至可以在nginx后面再次将其作为控制台应用程序进行自我托管.您也可以将asp.net应用程序托管在apache \ nginx下,而几乎不需要更改代码.

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.

半年前,我将大型项目移植"了从Windows服务器到CentOS 7服务器的两年开发,主要是通过将内容复制到centos并运行(几乎没有任何更改,而无需在mono下重新编译).当然,该项目具有许多第三方依赖项,这些依赖项的一些开发人员甚至都不知道单声道的存在.尽管如此,他们只是工作了.该解决方案有大约90个VS项目.

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.

当然,并不是每个复杂的项目都那么容易移植,尤其是当您经常使用本机库时,但通常情况并非如此.另外,如果您使用sql server,请注意,根据我的经验,mono中的sql server驱动程序非常糟糕.如果可以选择的话,我使用postgre并避免使用mono的sql server.以单声道方式处理图像也不是一件好事,越野车和不稳定.我避免不惜一切代价使用Bitmap类,而将其拼凑到imagemagick C api中.但是只有在进行认真且广泛的成像时,您才需要在那做,对于基本任务就可以了.

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.

长话短说,如今在2015年在Linux中运行.NET应用程序已不再是问题.

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

更新.如果您已经在2018年-除了在特定情况下使用Xamarin进行移动应用程序开发,使用Unity进行游戏开发或UI应用程序之类的特殊情况,几乎没有理由在linux上使用mono.如果只需要常规的console \ service应用程序(包括Web服务器),请使用.NET Core.据我的经验,它已经足够稳定,足够快地用于生产使用了,而越野车的数量甚至比mono还要少.在大多数情况下,将完整的.NET \ mono应用程序移植到.NET Core相对简单,尽管某些库可能在新平台上不可用.但是,如果您要开始新项目-毫无疑问,请选择.NET Core.

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.

这篇关于在2015年在Linux中运行.NET应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆