OpenRA / OpenRA

Open Source real-time strategy game engine for early Westwood games such as Command & Conquer: Red Alert written in C# using SDL and OpenGL. Runs on Windows, Linux, *BSD and Mac OS X.
https://www.openra.net
GNU General Public License v3.0
14.68k stars 2.68k forks source link

Target .NET standard 2.0 API #15954

Closed pchote closed 3 years ago

pchote commented 5 years ago

The modern .NET ecosystem targets the .NET standard API, which defines a common set of APIs implemented by .NET Framework, NET Core, and Mono. The early standards were rather weak, limited by the narrow API surface of .NET Core. The 2.0 standard added, I believe, all the APIs that we need for OpenRA.

In addition to supporting .NET Core and bringing our tooling up to modern standards, this would allow us to use some useful third party libraries:

The main blocker is packaging Mono (>= 5.4) in the Linux AppImages, which is already a requirement for proper AppImage compatibility. .NET 4.7.1 is required on Windows, but raising this requirement shouldn't affect our compatibility there.

pchote commented 5 years ago

16345 marked the completion of the first major phase to support this - we can now safely assume that all players will have a runtime that supports .NET standard 2.0.

Phase 2 is to merge and upgrade our windows and mono build processes, using msbuild and the newer vs2017-format csproj. The new csproj format trims all the fat and rivals the Makefile in terms of conciseness and readability (i.e. still a bit weird and obtuse, but good enough) so we shouldn't lose anything by doing this. I have a local prototype which I aim to clean up and PR during this release cycle.

Phase 2.5 should be to replace our custom dependency fetching scripts with nuget references. I don't like Nuget, but we can't justify not using it at this point - and its mandatory if we want to switch over to .NET core in the future. Research and tests will be required here to work out how to handle our platform-specific dependencies.

Phase 3 is to remove the last uses of non-standard-2.0 code so so that we can switch to <TargetFramework>netstandard2.0</TargetFramework>:

The game seems to otherwise run fine after hacking these out, so I don't expect any other major problems. This is a good motivation to investigate using Roslyn or another tool to compile the sync metadata during compilation, which I suspect will also help reduce the virus scanner false positives on Windows and reduce our load times.

pchote commented 4 years ago

16451 and related PRs completed phase 2 and #17744 completed phase 2.5.

pchote commented 4 years ago

The overall plan here has evolved a bit in the last year. Our goal is now to target netstandard2.1 as our baseline, with netcore3.1 as our primary runtime that is shipped inside our official packages. We aim to keep first-class (or as near as possible) support for mono to support older macOS, BSD, and anyone else who can't or doesn't want to run .NET Core.

The netstandard2.1 API includes System.Reflection.Emit, so solves the sync code incompatibility. It also includes new networking APIs that would apparently allow us to use TLS for the game network connections.

This amended plan brings in some new constraints to work around:

We don't yet have a consensus on exactly how to proceed, but my personal view (which may still contain factual inaccuracies/impossibilities) is that we should:

Mailaender commented 4 years ago

https://github.com/alanmcgovern/Mono.Nat/releases is back and it targets .NET Standard 2.0 now.

Leonardo-Ferreira commented 3 years ago

any news on this front? anyone working on this would like some help?

teinarss commented 3 years ago

any news on this front? anyone working on this would like some help?

https://github.com/OpenRA/OpenRA/pull/17989 but neither me or pchote are having much time right now to fix the last issues, something wrong on osx for example.

Leonardo-Ferreira commented 3 years ago

well, you're in luck! my workstation is OSX! care to speed me up to the "something wrong"? you're talking about the

Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does not match the assembly reference. (0x80131040) File name: 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

???

pchote commented 3 years ago

Fixed by #17989.