Unable to Link Godot.NET.Sdk Package While Testing Mono Pull Request on Ubuntu 20

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Luke Aaron

Hi all,

I’m trying to test a pull request (Rename ToneMapper to PostProcessor and add a 3D mode for post process viewport · godotengine/godot@3392520 · GitHub) using the guide from this link: Testing pull requests — Godot Engine (stable) documentation in English

I can run the editor and see my project without any issues.

However, when attempting a build, I encounter the following error. Although the downloaded ‘artifact’ includes a nuget folder, I’m unsure how to link it in Godot, and the documentation doesn’t seem to mention this step. I’m using Ubuntu 20:

         /home/luke/workspace/godot4/core-0.4b/core-0.4.csproj : error : Unable to find package Godot.NET.Sdk with version (= 4.1.0-dev)
   /home/luke/workspace/godot4/core-0.4b/core-0.4.csproj : error :   - Found 39 version(s) in nuget.org [ Nearest version: 4.0.2 ]

The pull request’s downloaded artifact appears to include nuget packages with the required name, but I’m not sure how to use them. As I’m relatively new to C#, I apologize if this issue is beyond the scope of Godot.

I’ve also tried creating a new blank project to ensure that it wasn’t an import problem, but I still get the same build error. Any assistance would be greatly appreciated!

:bust_in_silhouette: Reply From: Luke Aaron

After a bit of reading I think I may have sussed. created a nuget.config file in the project and added the following lines:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <packageSources>
        <add key="LocalNuGet" value="/home/luke/workspace/godot4/core-0.4b/packages" />
        <add key="NuGetOrg" value="https://api.nuget.org/v3/index.json" />
    </packageSources>
</configuration>

I’d copied the .nupkg files in this packes directory, though you can probably just reference the original directory.

:bust_in_silhouette: Reply From: vannongtinh

I’m currently working on fixing bugs in the Godot_mono_version_4.0, but I’m facing difficulties with the configuration process. I have followed all the steps provided in the Compiling with .NET guide, but unfortunately, it’s not functioning as expected.

Upon clicking the “build” button in the editor, I encountered two errors that are related to the “Godot.NET.Sdk/4.1.0-dev” package. The first error message states: Unable to find package Godot.Net.Sdk with version (=4.1.0-dev) - Found 43 version(s) in nuget.org [ Nearest 4.1.0-dev.1. This indicates that the specified package version cannot be located, and it suggests using the nearest available version.

The second error message states: The SDK 'Godot.NET.Sdk/4.1.0-dev' specified could not be found. This means that the specified SDK mentioned in the project file cannot be found on the machine.

The *.csproj file of the newly created project, which was built using the binary, displays the following settings:

<Project Sdk="Godot.NET.Sdk/4.1.0-dev">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <EnableDynamicLoading>true</EnableDynamicLoading>
    <RootNamespace>Empty.development</RootNamespace>
  </PropertyGroup>
</Project>

After spending a day troubleshooting, I realized that the instructions I followed were likely tailored for Linux, and since I am using Windows 10, that might be the reason why it’s not working. Furthermore, the example I referred to was missing the step “dotnet nuget add source,” which resulted in the error: “The SDK 'Godot.NET.Sdk/4.1.0-dev” occurrence.

I have revised the instructions to make them more accurate, and now it is working. Here are the revised steps:

  1. My intention is to debug the Godot source code, so I invoke scons with the following options:
scons dev_build=yes dev_mode=yes vsproj=yes module_mono_enabled=yes
  1. After completing step 1, running the editor will prompt a message
    stating “.NET runtime is missing.”
Failed to load .NET runtime
Unable to load .NET runtime, no compatible version was found.
Attempting to create/edit a project will lead to a crash.
Please install the .NET SDK 6.0 or later from
https://dotnet.microsoft.com/en-us/download and restart Godot.
This bug occurs because of missing the configuration file. Just continue with the steps below.

here is the bug report. To resolve this issue, I need to build .NET assemblies:

python ./modules/mono/build_scripts/build_assemblies.py --godot-output-dir=./bin --godot-platform=windows
  1. Then, generate glue sources as usual:
./bin/godot.windows.editor.dev.x86_64.mono.exe --headless --generate-mono-glue modules/mono/glue
  1. Re-build the .NET assemblies again. It is uncertain whether this
    step is necessary:
python ./modules/mono/build_scripts/build_assemblies.py --godot-output-dir=./bin --godot-platform=windows
  1. Ensure that the nuget source is clean:
dotnet nuget remove source MyLocalNugetSource
  1. Add the source. The path “bin\MyLocalNugetSource” will be generated
    in the subsequent step. Make sure to replace the path to the Godot
    project root directory with the appropriate path on your local
    machine. Note that the path must be an absolute path since relative
    paths cannot be passed to the nuget source command:
dotnet nuget add source "D:\VisualStudios\godot\bin\MyLocalNugetSource" --name MyLocalNugetSource
  1. To verify that the nuget source was added correctly and is pointing
    to the intended path, execute the following command:
dotnet nuget list source
  1. Generate the MyLocalNugetSource. After completing this step, the MyLocalNugetSource will be placed in the bin directory of the current directory.
python ./modules/mono/build_scripts/build_assemblies.py --godot-output-dir ./bin --push-nupkgs-local bin/MyLocalNugetSource

Now, you can run the editor and click “build” or “run” again to confirm that everything is functioning properly.

I have created a batch script to automate this process, assume the bug is fixed. Here is the script. Please save it as mono-compile.bat in the Godot source code directory you have cloned.

@echo off
setlocal enabledelayedexpansion

@echo Compiling with .NET ...
scons dev_build=yes dev_mode=yes vsproj=yes module_mono_enabled=yes
    
@echo Generate glue sources ...
./bin/godot.windows.editor.dev.x86_64.mono.exe --headless --generate-mono-glue modules/mono/glue

@echo Build .NET assemblies ...
python ./modules/mono/build_scripts/build_assemblies.py --godot-output-dir=./bin --godot-platform=windows

set "sourceName=MyLocalNugetSource"
set "expectedPath=%cd%\bin\MyLocalNugetSource"
set "found=false"

for /f "tokens=2" %%A in ('dotnet nuget list source') do (
    set "source=%%A"
    if "!source!"=="%sourceName%" (
        set "found=true"
    )
)

@echo Make sure nuget source is clean.
if "%found%"=="true" (
    dotnet nuget remove source MyLocalNugetSource
) else (

    echo The NuGet source "%sourceName%" does not exist, ignore this step.
)

@echo add source path ...
dotnet nuget add source "%expectedPath%" --name MyLocalNugetSource
@echo Generate MyLocalNugetSource.
python ./modules/mono/build_scripts/build_assemblies.py --godot-output-dir ./bin --push-nupkgs-local bin/MyLocalNugetSource