【发布时间】:2018-07-04 20:18:14
【问题描述】:
我正在使用 VS Code 使用 dotnet core 2.0 CLI 编写 Lambda 函数。
- VS 代码 v1.24.1
- dotnet Core CLI v2.1.200
问题
我无法让调试器使用我在 VS Code 中编写的函数在本地工作。
我在var body = request?.Body; 行上放置了一个断点(参见下面的 Function.cs 代码块)。然后,当我单击 VS Code 中 Debug 选项卡中的 start debugging 按钮时,我得到以下信息:
-------------------------------------------------------------------
You may only use the Microsoft .NET Core Debugger (vsdbg) with
Visual Studio Code, Visual Studio or Visual Studio for Mac software
to help you develop and test your applications.
-------------------------------------------------------------------
Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.7\System.Private.CoreLib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Loaded 'C:\Users\chris\Documents\Github\tcdevs\resource-it\client-management-lambda\ClientManagement.TestAsyncFunction\test\ClientManagement.TestAsyncFunction.Tests\bin\Debug\netcoreapp2.0\ClientManagement.TestAsyncFunction.Tests.dll'. Symbols loaded.
Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.7\System.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The program '[49584] ClientManagement.TestAsyncFunction.Tests.dll' has exited with code 0 (0x0).
函数.cs
Lambda 函数使用 APIGatewayEvents 包接受来自 API Gateway 的请求
public async Task<APIGatewayProxyResponse> FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
{
var body = request?.Body;
// do something asynchronously
return new APIGatewayProxyResponse()
{
Body = JsonConvert.SerializeObject(body),
StatusCode = 200,
Headers = new Dictionary<string, string>{ {"Content-Type", "application/json"} }
};
}
launch.json
我已将其配置为使用 Function.cs dll(由 vs 代码创建的文件正在命中测试项目)
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (lambda)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/ClientManagement.TestAsyncFunction/bin/Debug/netcoreapp2.0/ClientManagement.TestAsyncFunction.dll",
"args": [],
"cwd": "${workspaceFolder}/src/ClientManagement.TestAsyncFunction",
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
}
但我认为这种方法不适用于 dotnet core 2.0。我也做了很多谷歌搜索,几乎没有找到关于如何在 VS Code 中调试 dotnet core 2.0 函数的信息。
【问题讨论】:
标签: c# amazon-web-services visual-studio-code .net-core aws-lambda