如何在 dotnet c# 的 neovim DAP 配置中设置环境?

问题描述 投票:0回答:1

我正在尝试使用 neovim DAP 调试我的 c# 应用程序。这是我的配置

local dap = require('dap')

dap.adapters.coreclr = {
  type = 'executable',
  command = '/home/asd/netcoredbg/netcoredbg',
  args = { '--interpreter=vscode' },
}

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

当我使用 dll 运行 DAP 时,我收到这些错误

尝试使用

netcoredbg
cli工具单独,如下所示:
~/netcoredbg/netcoredbg --interpreter=cli -- dotnet run ./bin/Debug/net7.0/WebApi.dll environment=DevelopmentLocalhost
并且一切正常

所以我很确定我的 dap 配置是错误的。感谢您的帮助!

UPD:我在下面回答了我的实际问题。 但是!最后一个问题仍然存在:有没有办法设置

dap
以仅使用
launch.json
生成的
VsCode
以及如何做到这一点?

debugging .net-core vscode-debugger neovim coreclr
1个回答
0
投票

所以..我可以使用这样的配置:

...
    justMyCode = false,
    stopAtEntry = false,
    program = function()
      -- todo: request input from ui
      return "/path/to/your.dll"
    end,
    env = {
      ASPNETCORE_ENVIRONMENT = function()
        -- todo: request input from ui
        return "Development"
      end,
      ASPNETCORE_URLS = function()
        -- todo: request input from ui
        return "http://localhost:5050"
      end,
    },
    cwd = function()
        -- todo: request input from ui
        return vim.fn.getcwd()
    end,
...

所以这里关键的事情是我们使用

env
配置对象的
cs
属性来传递环境。就像其他字段一样,它可以是精确值,也可以是一个函数,例如从 ui 获取输入,然后用作 env 变量的值:

ASPNETCORE_ENVIRONMENT = "Development"

ASPNETCORE_ENVIRONMENT = function()
   return vim.fn.input("ASPNETCORE_ENVIRONMENT: ", "Development")
end,

另外,设置

cwd
也很重要,因为
appsettings.json
会在那里被搜索

cwd = function()
   return vim.fn.input("Workspace folder: ", vim.fn.getcwd() .. "/", "file")
end,
© www.soinside.com 2019 - 2024. All rights reserved.