Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add C# .NET 9 support #98334

Closed
HKunogi opened this issue Oct 19, 2024 · 10 comments
Closed

Add C# .NET 9 support #98334

HKunogi opened this issue Oct 19, 2024 · 10 comments

Comments

@HKunogi
Copy link
Contributor

HKunogi commented Oct 19, 2024

Tested versions

System information

Windows 11 Pro 27723

Issue description

The .NET 9 left preview and is on release-candidate state, due to this the godot global.json file which by default has "rollForward": "latestMajor", is jumping from .NET 8 to .NET 9 during the build and glue procedures, but godot itself cannot load .NET 9 binaries, due to changes on them from .NET 8 to .NET 9, we should either start adding .NET 9 binary support for godot (as in RC state it won't change the actual binary structure any further again on this version), or alter the global.json so it does not jump to RCs of new major releases. By default, by having the latest SDKs installed on the system, the godot will automatically try to use the .NET 9 and thus fail to load the resulting binaries afterwards.
It used to work perfectly while the .NET 9 SDK were marked as preview, after latest update from VS Studio Installer, which marked it as RC instead, this started happening.

Steps to reproduce

Simply have latest .NET SDK tools installed on your system and build normally.

Minimal reproduction project (MRP)

Its build issue, thus theres no MRP.

@raulsntos
Copy link
Member

Every Godot C# project targets net6.0 or netstandard2.0, so I'm not sure what you mean by building .NET 9 binaries. The latest .NET SDK should always be used to build the C# projects, these projects will still target the framework version specified in their .csproj so they should be compatible with .NET 6 or greater regardless of the SDK version used to build them.

I'm also not sure what you mean by adding .NET 9 binary support for Godot. As far as I know, Godot is already compatible with .NET 9. The only issue is Godot will struggle with prerelease versions (such as .NET 9 right now) which requires you to set the DOTNET_ROLL_FORWARD_TO_PRERELEASE environment variable to 1, but this is only needed while .NET 9 is a prerelease and will not be needed when the stable version is released on November.

I tested building the Godot C# projects with dotnet-sdk-9.0.100-rc.1.24452.12-linux-x64 and I had no issues.

@HKunogi
Copy link
Contributor Author

HKunogi commented Oct 19, 2024

Every Godot C# project targets net6.0 or netstandard2.0, so I'm not sure what you mean by building .NET 9 binaries. The latest .NET SDK should always be used to build the C# projects, these projects will still target the framework version specified in their .csproj so they should be compatible with .NET 6 or greater regardless of the SDK version used to build them.

I'm also not sure what you mean by adding .NET 9 binary support for Godot. As far as I know, Godot is already compatible with .NET 9. The only issue is Godot will struggle with prerelease versions (such as .NET 9 right now) which requires you to set the DOTNET_ROLL_FORWARD_TO_PRERELEASE environment variable to 1, but this is only needed while .NET 9 is a prerelease and will not be needed when the stable version is released on November.

I tested building the Godot C# projects with dotnet-sdk-9.0.100-rc.1.24452.12-linux-x64 and I had no issues.

It's not about building actual C# projects for godot, that works as long as you put the .NET 8 as target for it.
The issue is when you compiling the actual engine editor, when you generate the mono glue and then proceed to build_assemblies.py to build that mono glue.

@raulsntos
Copy link
Member

raulsntos commented Oct 19, 2024

Sorry, that's what I meant. I'm running build_assemblies.py with .NET 9 RC1 and then launching the Godot editor with no issues.

Every Godot engine assembly targets net6.0 or netstandard2.0, and can be compiled with .NET 9. User projects should be able to target net6.0 or greater (including net9.0).

@HKunogi
Copy link
Contributor Author

HKunogi commented Oct 19, 2024

Sorry, that's what I meant. I'm running build_assemblies.py with .NET 9 RC1 and then launching the Godot editor with no issues.

Every Godot engine assembly targets net6.0 or netstandard2.0, and can be compiled with .NET 9. User projects should be able to target net6.0 or greater (including net9.0).

For me this started happening after this latest update which is RC2.
Godot also fails to load project binaries if they using .NET 9 AOT, but works fine with .NET 8 AOT.
Here the log from the editor itself:
Godot Engine v4.4.dev.mono.custom_build (c) 2007-present Juan Linietsky, Ariel Manzur & Godot Contributors. D:/Source/Other/gd-engine/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs:417 - System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. File name: 'System.Runtime, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' at GodotTools.ProjectEditor.ProjectUtils.Open(String path) at GodotTools.GodotSharpEditor.ApplyNecessaryChangesToSolution() in D:\Source\Other\gd-engine\modules\mono\editor\GodotTools\GodotTools\GodotSharpEditor.cs:line 417
This never happened prior to the latest update from today.

@AdamantiumKiwi
Copy link

AdamantiumKiwi commented Oct 24, 2024

I have a similar issue.

I am starting to learn Godot - I am a somewhat experienced C# developer.

On Windows 11 - I installed Godot , created a new project, and selected VS as the editor.

I have VS2022 17.12.0 Preview 4 (latest preview as at this time).

dotnet --list-sdks shows these (earlier installations up to 7.0,120 are removed for brevity; no 8.x.x are present):

9.0.100-preview.6.24328.19 [C:\Program Files\dotnet\sdk]
9.0.100-rc.2.24474.11 [C:\Program Files\dotnet\sdk]

I created a project, added a root node, clicked the Add script button.

This was shown in the Ouput window:
Godot Engine v4.3.stable.mono.official (c) 2007-present Juan Linietsky, Ariel Manzur & Godot Contributors. --- Debug adapter server started on port 6006 --- --- GDScript language server started on port 6005 --- New Scene Root /root/godot/modules/mono/editor/GodotTools/GodotTools/CsProjOperations.cs:13 - System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. File name: 'System.Runtime, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' at GodotTools.ProjectEditor.ProjectGenerator.GenAndSaveGameProject(String dir, String name) at GodotTools.CsProjOperations.GenerateGameProject(String dir, String name) in /root/godot/modules/mono/editor/GodotTools/GodotTools/CsProjOperations.cs:line 13 modules/mono/csharp_script.cpp:2854 - C# project could not be created; cannot add file: 'res://Node2d.cs'. Attach Script

VS2022 is opened but with no solution/code etc.

@raulsntos
Copy link
Member

To allow pre-releases (such as .NET 9), set the DOTNET_ROLL_FORWARD_TO_PRERELEASE environment variable to 1.

@Framebuffers
Copy link

Framebuffers commented Oct 29, 2024

Hi, don't know if it's useful or not, but I have been working with a project targeted at .NET 9.0 and it's been working rather well so far. Haven't had any issues so far.

I am running a 4.3-based self-compiled build, but it doesn't have anything but #79731 baked in. If I find something weird, I can update this thread. But I can vow for .NET 9 working flawlessly on a greenfield 4.3 project.

EDIT: for context

$ dotnet version
9.0.100-rc.2.24474.11

$ uname -a
Linux ralsei 6.8.0-47-generic #47-Ubuntu SMP PREEMPT_DYNAMIC Fri Sep 27 21:40:26 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

@HKunogi
Copy link
Contributor Author

HKunogi commented Nov 4, 2024

Hi, don't know if it's useful or not, but I have been working with a project targeted at .NET 9.0 and it's been working rather well so far. Haven't had any issues so far.

I am running a 4.3-based self-compiled build, but it doesn't have anything but #79731 baked in. If I find something weird, I can update this thread. But I can vow for .NET 9 working flawlessly on a greenfield 4.3 project.

EDIT: for context

$ dotnet version
9.0.100-rc.2.24474.11

$ uname -a
Linux ralsei 6.8.0-47-generic #47-Ubuntu SMP PREEMPT_DYNAMIC Fri Sep 27 21:40:26 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Did you try AOT with it? afaik it wont load on .NET 9 but will on .NET 8.

To allow pre-releases (such as .NET 9), set the DOTNET_ROLL_FORWARD_TO_PRERELEASE environment variable to 1.

I'll give a try. Edit: This indeed allowed it to compile and run, thanks. But still won't load AOT binaries i guess.

@Calinou Calinou changed the title C# .NET 9 Add C# .NET 9 support Nov 4, 2024
@raulsntos
Copy link
Member

But still won't load AOT binaries i guess.

Works fine for me. What error are you getting?

@HKunogi
Copy link
Contributor Author

HKunogi commented Nov 13, 2024

But still won't load AOT binaries i guess.

Works fine for me. What error are you getting?

It used to say that the methods were not found, but after the latest .net update it seems to have been solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants