Search code examples
continuous-integrationmonogodot

Can't build Godot mono project "namespace name 'Godot' could not be found"


I'm trying to build a Godot mono project that I've just cloned from my repo that works on my other machine.

When I try to build in Visual Studio I get the error

 error CS0246: The type or namespace name 'Godot' could not be found (are you missing a using directive or an assembly reference?)

I can replicate this by creating a basic empty scene project in Godot and opening the new solution in Visual Studio and trying to build.


Solution

  • There are a few scenarios where this issue can present itself:

    • Cloning from a repo where the project builds elsewhere but on this new machine it doesn't
    • Trying a new IDE: Visual Studio, Rider, VS Code
    • New team members joining
    • On continuous integration systems

    The solution is in a response from KellyThomas on a Github issue here

    The godot mono assemblies are placed in your project's .mono/assemblies directory during the process of building your project.

    scene (play buttons are in top left corner of the godot window) or clicking the build button on the mono panel (center-bottom in the same stack as output, debugger etc).

    1. running your project / scene (play buttons are in top left corner of the godot window) or
    2. clicking the build button on the mono panel (center-bottom in the same stack as output, debugger etc).

    So the reason the project isn't building is that your IDE or build system doesn't have the required dll that is normally put there by the Godot program itself when you run a build from there.

    For a local Dev machine the solution is to build or run the project in Godot once and it will place the dll in the correct folder where it will remain allowing builds to be created by other applications ie Visual Studio or Rider(if you use the Rider plugin for Godot I believe it will create the dll for you).

    lovely red circles

    On a CI the approach is a bit different as we're starting fresh every time and we don't necessarily want to run Godot Build when we can use something like MSBuild.

    My solution to this is to store a copy of the required DLL outside the working directory and copy it to the build folder before the MSBuild step is run.

    The required DLL for building Godot 3.4.4 Mono projects at the time of writing is GodotSharp.dll. I suspect you will have to copy a new version of this DLL every time you upgrade Godot.

    Do a manual one time build of a Godot project to generate the DLL (basic hello world is fine). After building the project in the Godot Application the DLL is stored in a folder next to the solution file (.sln) for the project. The folder depends on the configuration of your build.

    .mono/assemblies/Debug
    .mono/assemblies/Release
    

    In OSX the .mono folder is hidden, press cmd + shift + . to see the folder in the finder.

    This is how I get the file copied to the correct folder on Azure Devops using a yaml pipeline.

    - task: CopyFiles@2
          inputs:
            SourceFolder: $(Agent.BuildDirectory)/GodotDlls/3.4.3
            Contents: '**'
            TargetFolder: $(binariesPath)/.mono/assemblies/Release