日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

Dapr + .NET 实战(九)本地调试

發(fā)布時(shí)間:2023/12/4 asp.net 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Dapr + .NET 实战(九)本地调试 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

前幾節(jié)開發(fā)Dapr應(yīng)用程序時(shí),我們使用 dapr cli 來啟動(dòng)dapr服務(wù),就像這樣:

dapr run --dapr-http-port 3501 --app-port 5001 --app-id frontend dotnet .\FrontEnd\bin\Debug\net5.0\FrontEnd.dll

如果你想要通過dapr調(diào)試服務(wù)呢?在這里使用 dapr 運(yùn)行時(shí)(daprd) 來幫助實(shí)現(xiàn)這一點(diǎn)。具體原理就是先從命令行中運(yùn)行符合正確參數(shù)的 daprd,然后啟動(dòng)您的代碼并附加調(diào)試器。

1.配置launch.json

vscode打開項(xiàng)目,并創(chuàng)建launch.json

?修改launch.json的preLaunchTask,自定義名字,preLaunchTask將引用在 tasks.json 文件中定義的任務(wù)。

{// Use IntelliSense to learn about possible attributes.// Hover to view descriptions of existing attributes.// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0","configurations": [{"name": "Frontend-.NET Core Launch (web)","type": "coreclr","request": "launch",//"preLaunchTask": "build","preLaunchTask": "daprd-frontend","program": "${workspaceFolder}/FrontEnd/bin/Debug/net5.0/FrontEnd.dll","args": [],"cwd": "${workspaceFolder}/FrontEnd","stopAtEntry": false,"serverReadyAction": {"action": "openExternally","pattern": "\\bNow listening on:\\s+(https?://\\S+)"},"env": {"ASPNETCORE_ENVIRONMENT": "Development"},"sourceFileMap": {"/Views": "${workspaceFolder}/Views"}},{"name": ".NET Core Attach","type": "coreclr","request": "attach"}] }

2.配置task.json

需要在task.json文件中定義一個(gè) daprd task和問題匹配器(problem matcher)。這里有兩個(gè)通過上述 preLaunchTask 成員引用。在 dpred -frontend task下,還有一個(gè)dependsOn成員,它引用build任務(wù),以確保最新的代碼正在運(yùn)行/調(diào)試。用了 problemMatcher,這樣當(dāng) daprd 進(jìn)程啟動(dòng)和運(yùn)行時(shí),VSCode 就能夠知道。

{"version": "2.0.0","tasks": [{"label": "build","command": "dotnet","type": "process","args": ["build","${workspaceFolder}/FrontEnd/FrontEnd.csproj","/property:GenerateFullPaths=true","/consoleloggerparameters:NoSummary"],"problemMatcher": "$msCompile"},{"label": "publish","command": "dotnet","type": "process","args": ["publish","${workspaceFolder}/FrontEnd/FrontEnd.csproj","/property:GenerateFullPaths=true","/consoleloggerparameters:NoSummary"],"problemMatcher": "$msCompile"},{"label": "watch","command": "dotnet","type": "process","args": ["watch","run","${workspaceFolder}/FrontEnd/FrontEnd.csproj","/property:GenerateFullPaths=true","/consoleloggerparameters:NoSummary"],"problemMatcher": "$msCompile"},{"label": "daprd-frontend","command": "daprd","args": ["-app-id","frontend","-app-port","5001","-dapr-http-port","3501","-placement-host-address","localhost:6050","-components-path","C:\\Users\\chesterychen\\.dapr\\components"],"isBackground": true,"problemMatcher": {"pattern": [{"regexp": ".","file": 1,"location": 2,"message": 3}],"background": {"beginsPattern": "^.*starting Dapr Runtime.*","endsPattern": "^.*waiting on port.*"}},"dependsOn": "build"},] }

因?yàn)闆]有使用?dapr?run* cli 命令, 所以運(yùn)行 daprd list 命令將不會(huì)顯示當(dāng)前正在運(yùn)行的應(yīng)用列表。

3.調(diào)試

在StateController.GetAsync中新增斷點(diǎn),運(yùn)行并調(diào)用http://192.168.43.94:3501/v1.0/invoke/frontend/method/State。

4.不用vscode調(diào)試

cmd運(yùn)行以下命令,監(jiān)聽5001端口

daprd run -dapr-http-port 3501 -app-port 5001 -app-id frontend -placement-host-address localhost:6050 -components-path C:\\Users\\chesterychen\\.dapr\\components

然后直接vs運(yùn)行項(xiàng)目,即可調(diào)試

總結(jié)

以上是生活随笔為你收集整理的Dapr + .NET 实战(九)本地调试的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。