:::' ####:::::' ######::' ######:::::
::::' ##:::::: ##::: ##: ##::: ##::::
::::: ##:::::: ##::: ##: ##::::::::::
::::: ##:::::: ##::: ##: ##:: ###::::
::::. ##:: ##: ##::: ##: ##::. ##::::
:::: ########:. ######::. ######:::::
::::........:::......::::......::::::

Configure Neovim debug adapter for dotnet on macOS

Ever since moving to Neovim I’ve been printf() debugging. This approach is usually good enough for my side projects at home, but I’m not going to lie, there are times when I miss step debugging.

I don’t code in C# much anymore. But I like the idea of having a setup for developing C# application on macOS when I want to, without having to install VS Code. And having step debugging availiable is a part of that setup. So let’s dive into how I configured the debug adapter in Neovim.

Prerequisites

You need Neovim, obviously. I will not go into the details of setting up nvim-dap. If you are following along, I assume you have nvim-dap in place already.

First, let’s make sure dotnet and cmake are installed.

dotnet --version
# 9.0.203
cmake --version
# cmake version 4.0.1

Note! When installing CMake manually you have to make sure the PATH is updated aswell.

PATH="/Applications/CMake.app/Contents/bin:$PATH"
export PATH

Building the binaries

Now clone netcoredb repository and create a build directory.

cd netcoredbg
mkdir build
cd build

And configure the build.

CC=clang CXX=clang++ cmake ..

If you got a newer version of CMake, like I do, you might run into this error.

CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 has been removed from CMake.

  Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
  to tell CMake that the project requires at least <min> but has been updated
  to work with policies introduced by <max> or earlier.

  Or, add -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to try configuring anyway.


-- Configuring incomplete, errors occurred!

Solving this error is easy enough. Just a small update in CMakeList.txt, a file found in the root of /netcoredbg. Open it up and replace the version at the top.

# Replace
cmake_minimum_required(VERSION 2.8.12.2)

# With
cmake_minimum_required(VERSION 3.5)

I also had to update another CMakeLists.txt file located in the directory /netcoredbg/third_party/linenoise-ng

# Replace
cmake_minimum_required(VERSION 2.6)

# With
cmake_minimum_required(VERSION 3.5)

Let’s go back to the /build directory and configure the build once again.

CC=clang CXX=clang++ cmake ..

This time success!

With everything configured, run make and make install. If everything is successful the output is placed in the directory /usr/local/netcoredbg.

make
make install

Configure Neovim

The DAP configuration in Neovim is pretty straight forward, more information can be found here. My configuration looks like this.

dap.adapters.coreclr = {
    type = "executable",
    command = "/usr/local/netcoredbg",
    args = { "--interpreter=vscode" }
}

dap.configurations.cs = {
    {
        type = "coreclr",
        name = "Launch",
        request = "launch",
        program = function()
            return vim.fn.input("Path to dll: ", vim.fn.getcwd() .. "/bin/Debug/", "file")
        end
    }
}

Now I can open up a C# project and fire up the debugger like old times! 🎉