How to write programs in C# .NET, to run them on Linux/Wine/Mono?

前端 未结 5 880
攒了一身酷
攒了一身酷 2020-12-08 08:02

In this particular case I need to run .complicated NET application for Linux. By complicated i mean - that project was developed for 3 years and i don\'t wa

相关标签:
5条回答
  • 2020-12-08 08:42

    In this post i shortened and combined all information i learned from others in this thread.

    1. Open source impementation of .NET for Linux is called Mono.

    2. Compatibility is well documented (see links below). Mono supports LINQ, threading and some other complicated features.

    3. It even supports InteropServices. Its possible to use DllImport on linux library (!), like libc.so for example.

    4. Mono can support Android and iOS (they are Linux based, right?)

    5. There is a tool for Mono compatibility analysis called MoMA (Mono Migration Analyzer)

    The Mono Migration Analyzer (MoMA) tool helps you identify issues you may have when porting your .Net application to Mono. It helps pinpoint platform specific calls (P/Invoke) and areas that are not yet supported by the Mono project.

    Useful links:

    Mono - home page

    Mono - page with documentation

    Mono - compatibility page

    MoMA - Mono Migration Analysis page

    0 讨论(0)
  • 2020-12-08 08:42

    We have a couple of .net applications that run on Windows or Linux with Mono.

    You can develop in VisualStudio if you want, it is not necessary to use the Mono development environment. Only the runtime mono libraries are required in order to run .net applications on Linux.

    We use net 2.0 target to compile these apps in VisualStudio, because mono is nearly 100% compatible with .net 2.0. Mono also implements APIS from later .net versions, but not all and not as complete. If you use features of newer versions than 2.0, you should check if these are supported or use the Mono compatibility analysis tool. You can also use Mono develop instead of Visual Studio, my predecessor was doing that; the result is pretty much the same, and I prefer to use Visual Studio instead.

    We didn't find any major trouble, and the apps are relatively complex, heavily multithreaded, async I/O, WinForms, sockets, serial ports, etc.

    Some app used .net libraries that are not available in MS .net, but all these can be installed on Windows as well so that there is no problem to run these apps in Windows.

    Hope that helps,

    0 讨论(0)
  • 2020-12-08 08:46

    You can develop C# applications on linux with .NET Core: https://www.microsoft.com/net/core

    After you install it, type dotnet new in your terminal to get a list of application templates which can be generated for you to start.

    As of .NET Core 2.0 today, this is the list:

    Templates                                         Short Name       Language          Tags               
    --------------------------------------------------------------------------------------------------------
    Console Application                               console          [C#], F#, VB      Common/Console     
    Class library                                     classlib         [C#], F#, VB      Common/Library     
    Unit Test Project                                 mstest           [C#], F#, VB      Test/MSTest        
    xUnit Test Project                                xunit            [C#], F#, VB      Test/xUnit         
    ASP.NET Core Empty                                web              [C#], F#          Web/Empty          
    ASP.NET Core Web App (Model-View-Controller)      mvc              [C#], F#          Web/MVC            
    ASP.NET Core Web App                              razor            [C#]              Web/MVC/Razor Pages
    ASP.NET Core with Angular                         angular          [C#]              Web/MVC/SPA        
    ASP.NET Core with React.js                        react            [C#]              Web/MVC/SPA        
    ASP.NET Core with React.js and Redux              reactredux       [C#]              Web/MVC/SPA        
    ASP.NET Core Web API                              webapi           [C#], F#          Web/WebAPI         
    global.json file                                  globaljson                         Config             
    Nuget Config                                      nugetconfig                        Config             
    Web Config                                        webconfig                          Config             
    Solution File                                     sln                                Solution           
    Razor Page                                        page                               Web/ASP.NET        
    MVC ViewImports                                   viewimports                        Web/ASP.NET        
    MVC ViewStart                                     viewstart                          Web/ASP.NET        
    

    The current latest version is 2.0.

    0 讨论(0)
  • 2020-12-08 08:48

    Have you read about Mono.NET on http://www.mono-project.com?

    It allows you to write .NET apps for Linux with minor differences over the Microsoft implementation. I don't think wine will cope with any of the .NET components.

    Just read the documentation before and you have a go.

    PS: This also gives you the compatibility list between mono and .NET. http://www.mono-project.com/Compatibility and MoMA(mono migration analyzer) is a tool that will scan any .NET app already created to see if its compatible to deploy on linux.

    0 讨论(0)
  • 2020-12-08 08:48

    You can install the full .Net Framework 4.x in wine using winetricks, then run your app.

    Wine supports serial ports, so I don't see any inconvenience.

    I made a video showing this:

    https://www.youtube.com/watch?v=60yyWBLXv1k

    In the video, you can see the windows taskbar. Don't worry about it. This is because it is running in WSL2. But these steps work perfectly in Linux.

    Regards

    0 讨论(0)
提交回复
热议问题