.net程序如何打开 linux,如何在c# .NET中編寫程序,在Linux/Wine/Mono上運行它們?

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 want to write it again in java or something else and develop and support both, .NET and Java version later.

在這種情況下,我需要為Linux運行. complex NET應用程序。我的意思是,這個項目已經開發了3年了,我不想再用java或其他東西來編寫它,然后開發和支持。net和java版本。

Application is generating mouse and keyboard events (by winapi/dll import) and uses serial port. I have also few timers for delays - for serial port communication (10-20ms, i dont need big precision here).

應用程序正在生成鼠標和鍵盤事件(通過winapi/dll導入)並使用串口。對於串行端口通信,我的計時器也很少(10-20ms,這里不需要很大的精度)。

The rest is just a lot of simple code, nothing special, no weird controls, no directx etc.

剩下的只是一些簡單的代碼,沒有什么特別的,沒有奇怪的控件,沒有directx等等。

What should i expect? Will this work?

我應該期待什么呢?這工作嗎?

If some part of code will fail - i can change it a little, make network connection between .net app and mini-application on linux that i can write for sending mouse and keyboard events, or RS232 communication.

如果代碼的某些部分失敗了——我可以稍微改變一下,在.net應用程序和linux上的迷你應用程序之間建立網絡連接,我可以為發送鼠標和鍵盤事件或RS232通信而編寫。

Additionally i want to ask about Wine and .NET in general:

另外,我想問一下關於Wine和。net的一般情況:

How to write .NET applications that should run on Linux/Wine/Mono?

如何編寫應該在Linux/Wine/Mono上運行的.NET應用程序?

which version of framework? (1.x, 2.0 or can i use 3.5?)

哪個版本的框架?(1。x 2.0還是3。5)

what should i avoid (imports from windows dll? timers?)

我應該避免什么(從windows dll導入?計時器?)

Edit/moved from comment:

編輯/從評論:

I saw mono few years ago, but it was terrible. Now i see it growed up, supports LINQ, Threading and other complicated features. In addition now help looks really serious. Im not accepting answer yet, because i see that people still posting very useful links. If this question gets many +1 i will rewrite it and maybe this will help others.

我幾年前見過mono,但是很糟糕。現在我看到它已經成熟,支持LINQ、線程和其他復雜的特性。此外,現在幫助看起來真的很嚴重。我現在還不接受答案,因為我看到人們仍然張貼非常有用的鏈接。如果這個問題得到許多+1,我將重寫它,也許這會幫助其他人。

I hope someone here have some practical experience with .NET on linux here...

我希望在座的各位能有linux上的。net的實際經驗……

4 个解决方案

#1

17

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

你讀過Mono嗎?在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.

它允許您為Linux編寫. net應用程序,與Microsoft實現稍有不同。我認為wine不會處理任何。net組件。

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.

這也提供了mono和。net之間的兼容性列表。http://www.mono-project.com/Compatibility和MoMA(mono migration analyzer)是一個工具,它將掃描任何已經創建的。net應用程序,看看它是否與linux上的部署兼容。

#2

4

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

在這篇文章中,我把從別人那里學到的所有信息都縮短了。

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

. net對Linux的開源嵌入被稱為Mono。

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

兼容性有很好的文檔記錄(見下面的鏈接)。Mono支持LINQ、線程和其他一些復雜的特性。

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

它甚至支持InteropServices。可以在linux庫(!)上使用DllImport(!),比如libc。舉個例子。

Mono can supports Android and iOS (they are Linux based, right?)

Mono可以支持Android和iOS(它們是基於Linux的,對嗎?)

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

有一個用於Mono兼容性分析的工具叫做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.

Mono遷移分析器(MoMA)工具可以幫助您識別在將. net應用程序移植到Mono時可能遇到的問題。它幫助確定平台特定的調用(P/Invoke)和Mono項目尚未支持的領域。

Useful links:

有用的鏈接:

Mono -主頁

單張頁與文檔

Mono -頁面的兼容性

MoMA - Mono遷移分析頁面

#3

3

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

我們有幾個在Windows或Linux上運行的。net應用程序。

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.

如果您願意,您可以在VisualStudio中進行開發,不需要使用Mono開發環境。只有運行時mono庫才能在Linux上運行。net應用程序。

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.

我們使用net 2.0 target在VisualStudio中編譯這些應用程序,因為mono幾乎100%兼容。net 2.0。Mono還實現了后來。net版本的api,但不是全部,也不是全部。如果您使用的是新版本的特性,而不是2.0,您應該檢查這些特性是否支持或使用Mono兼容性分析工具。你也可以使用Mono開發而不是Visual Studio,我的前任就是這樣做的;結果基本相同,我更喜歡使用Visual Studio。

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

我們沒有發現任何大的問題,並且應用程序是相對復雜的,大量多線程的,異步I/O, WinForms, sockets,串行端口,等等。

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.

一些應用程序使用。net庫,這些庫在MS .net中不可用,但所有這些都可以安裝在Windows上,這樣在Windows中運行這些應用程序就沒有問題了。

Hope that helps,

希望有所幫助,

#4

0

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

你可以使用。net核心的linux開發c#應用程序: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.

安裝后,在終端中鍵入dotnet new,獲取可以為啟動生成的應用程序模板列表。

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

在。net核心2.0的今天,這是一個列表:

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.

最新版本是2.0。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值