godotengine / godotengine/godot

Dotnet Sdk not updating when exporting

Open
#89,792 0 comments 0 reactions 0 assignees View on GitHub
bug needs testing topic:dotnet topic:export
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

Godot v4.3.dev.mono (e6d09ef1c)

### System information

Godot v4.3.dev.mono (e6d09ef1c) - Pop!_OS 22.04 LTS - Wayland - Vulkan (Forward+) - dedicated Intel(R) Arc(tm) A750 Graphics (DG2) () - AMD Ryzen 7 5800X 8-Core Processor (16 Threads)

### Issue description

This was a very tricky one to debug. Mainly because the dotnet nuget builds when building from source seem to be updating the godot engine build correctly. However, when exporting (at least for Linux) they do not seem to update. In my case, I had an old cache from last year. And as a result, my linux exports where segfaulting. The only way to seem to get the the export to take the new dotnet builds is to delete the dotnet build outputs in the mono module.

Fortunately a bash script can take care of cleaning this for us since ``dotnet clean`` does not seem to work and the ``--push-nupkgs-local`` arg as described here also doesn't seem to work: https://docs.godotengine.org/en/stable/contributing/development/compiling/compiling_with_dotnet.html#nuget-packages

This script will delete all folders ignored by git in the folder passed to it:

```bash
#!/bin/bash

set -e

prev_pwd="$PWD"

dir_to_clean="$1"
cd "$dir_to_clean"
echo "cleaning directory: $dir_to_clean"
files_to_remove="$(git status . --ignored --short)"

if [[ "$files_to_remove" == "" ]]
then
echo "$dir_to_clean: nothing to remove"
exit 0
fi

echo "Removing the following files and folders:"
echo "${files_to_remove[@]}"

# This command removes all files that are gitignored. This is useful for removing files that
# ``scons --clean`` doesn't remove such as the mono glue.
#
# Explanation of commands:
#
# Lists all the files and folders that are being ignored due .gitignore
# git status --ignored --short
#
# Removes the !! that ``git status --ignored --short`` outputs.
# NOTE: This could be an issue if we ever name a file or folder with !
# sed 's/!//g'
#
# Replaces all newline charactes with a ' ' so ``git status --ignored --short`` is space delimited
# tr '\n' ' '
#
# Removes all of the files and folders returned after formatting the output
# rm -rf
#
rm -rf $(echo "${files_to_remove[@]}" | sed 's/!//g' | tr '\n' ' ')

cd "$prev_pwd"
```

And it can be called like this:

```bash
# Clean the dotnet build cache because the cache is not being cleared as the godot documentation
# suggests it should. And this is just another level of certainty that the cache is cleared.
"$dir/clean-ignore.sh" godot/modules/mono/glue/GodotSharp
"$dir/clean-ignore.sh" godot/modules/mono/editor/Godot.NET.Sdk
"$dir/clean-ignore.sh" godot/modules/mono/editor/GodotTools
```

### Steps to reproduce

1. Build godot mono from source.
1. Build the Linux export template for mono. Then export a build.
1. Make a change to the C# code. Ideally something we know will get called like the generated c# code in godot/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/GodotPluginsInitializerGenerator.cs. In my case, I added a ``Console.WriteLine("Hello")`` inside ``InitializeFromGameProject`` so it looks like:

```cs
string source =
@"using System;
using System.Runtime.InteropServices;
using Godot.Bridge;
using Godot.NativeInterop;

namespace GodotPlugins.Game
{
internal static partial class Main
{
[UnmanagedCallersOnly(EntryPoint = ""godotsharp_game_main_init"")]
private static godot_bool InitializeFromGameProject(IntPtr godotDllHandle, IntPtr outManagedCallbacks,
IntPtr unmanagedCallbacks, int unmanagedCallbacksSize)
{
Console.WriteLine("Hello");
try
{
DllImportResolver dllImportResolver = new GodotDllImportResolver(godotDllHandle).OnResolveDllImport;

var coreApiAssembly = typeof(global::Godot.GodotObject).Assembly;

NativeLibrary.SetDllImportResolver(coreApiAssembly, dllImportResolver);

NativeFuncs.Initialize(unmanagedCallbacks, unmanagedCallbacksSize);

ManagedCallbacks.Create(outManagedCallbacks);

ScriptManagerBridge.LookupScriptsInAssembly(typeof(global::GodotPlugins.Game.Main).Assembly);

return godot_bool.True;
}
catch (Exception e)
{
global::System.Console.Error.WriteLine(e);
return false.ToGodotBool();
}
}
}
}
";
```

Then rebuild the c# glue and assemblies.

Docs here: https://docs.godotengine.org/en/stable/contributing/development/compiling/compiling_with_dotnet.html#building-the-managed-libraries

And here: https://docs.godotengine.org/en/stable/contributing/development/compiling/compiling_with_dotnet.html#nuget-packages

### Minimal reproduction project (MRP)

NA

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.