Visual Studio Code 个人常用优化设置
一、C:\Users\用户名\AppData\Roaming\Code\User\settings.json
{ "editor.minimap.enabled": false, "security.workspace.trust.enabled": false, "window.restoreWindows": "none", "workbench.localHistory.enabled": false, "workbench.sideBar.location": "right", "workbench.startupEditor": "newUntitledFile", "chat.commandCenter.enabled": false, "files.autoGuessEncoding": true }
二、处理异常日志,关键字换行异常内容,方便检索
三、格式化 C# 代码(大括号不换行)
1、在 C:\Users\用户名\.omnisharp\ 目录下创建 omnisharp.json
2、粘贴下面内容到omnisharp.json
{ "//": "https://github.com/OmniSharp/omnisharp-roslyn/wiki/Configuration-Options", "FormattingOptions": { "EnableEditorConfigSupport": false, "OrganizeImports": true, "NewLine": "\n", "UseTabs": false, "TabSize": 4, "IndentationSize": 4, "SpacingAfterMethodDeclarationName": false, "SpaceWithinMethodDeclarationParenthesis": false, "SpaceBetweenEmptyMethodDeclarationParentheses": false, "SpaceAfterMethodCallName": false, "SpaceWithinMethodCallParentheses": false, "SpaceBetweenEmptyMethodCallParentheses": false, "SpaceAfterControlFlowStatementKeyword": true, "SpaceWithinExpressionParentheses": false, "SpaceWithinCastParentheses": false, "SpaceWithinOtherParentheses": false, "SpaceAfterCast": false, "SpacesIgnoreAroundVariableDeclaration": false, "SpaceBeforeOpenSquareBracket": false, "SpaceBetweenEmptySquareBrackets": false, "SpaceWithinSquareBrackets": false, "SpaceAfterColonInBaseTypeDeclaration": true, "SpaceAfterComma": true, "SpaceAfterDot": false, "SpaceAfterSemicolonsInForStatement": true, "SpaceBeforeColonInBaseTypeDeclaration": true, "SpaceBeforeComma": false, "SpaceBeforeDot": false, "SpaceBeforeSemicolonsInForStatement": false, "SpacingAroundBinaryOperator": "single", "IndentBraces": false, "IndentBlock": true, "IndentSwitchSection": true, "IndentSwitchCaseSection": true, "IndentSwitchCaseSectionWhenBlock": true, "LabelPositioning": "oneLess", "WrappingPreserveSingleLine": true, "WrappingKeepStatementsOnSingleLine": true, "NewLinesForBracesInTypes": false, "NewLinesForBracesInMethods": false, "NewLinesForBracesInProperties": false, "NewLinesForBracesInAccessors": false, "NewLinesForBracesInAnonymousMethods": false, "NewLinesForBracesInControlBlocks": false, "NewLinesForBracesInAnonymousTypes": false, "NewLinesForBracesInObjectCollectionArrayInitializers": false, "NewLinesForBracesInLambdaExpressionBody": false, "NewLineForElse": false, "NewLineForCatch": false, "NewLineForFinally": false, "NewLineForMembersInObjectInit": false, "NewLineForMembersInAnonymousTypes": false, "NewLineForClausesInQuery": false } }
四、一次运行多个项目
1、粘贴下面内容到xxx\.vscode\launch.json
{ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": ".NET Core Launch (console)", "type": "coreclr", "request": "launch", "preLaunchTask": "build", "program": "${workspaceFolder}/Test/bin/Debug/net5.0/Test.dll", "args": [], "cwd": "${workspaceFolder}/Test", "stopAtEntry": false, "console": "externalTerminal" }, { "name": ".NET Core Launch (grpc_server)", "type": "coreclr", "request": "launch", "preLaunchTask": "build_grpc_server", "program": "${workspaceFolder}/Test_gRPC_Server/bin/Debug/net5.0/Test_gRPC_Server.dll", "args": [], "cwd": "${workspaceFolder}/Test_gRPC_Server", "stopAtEntry": false, "console": "integratedTerminal", "internalConsoleOptions": "neverOpen", "serverReadyAction": { "action": "openExternally", "pattern": "\\bNow listening on:\\s+(https?://\\S+)" }, "env": { "ASPNETCORE_ENVIRONMENT": "Development" }, "sourceFileMap": { "/Views": "${workspaceFolder}/Views" } }, { "name": ".NET Core Launch (grpc_client)", "type": "coreclr", "request": "launch", "preLaunchTask": "build_grpc_client", "program": "${workspaceFolder}/Test_gRPC_Client/bin/Debug/net5.0/Test_gRPC_Client.dll", "args": [], "cwd": "${workspaceFolder}/Test_gRPC_Client", "stopAtEntry": false, "console": "externalTerminal" }, { "name": ".NET Core Launch (webapi_server)", "type": "coreclr", "request": "launch", "preLaunchTask": "build_webapi_server", "program": "${workspaceFolder}/Test_WebAPI_Server/bin/Debug/net5.0/Test_WebAPI_Server.dll", "args": [], "cwd": "${workspaceFolder}/Test_WebAPI_Server", "stopAtEntry": false, "console": "integratedTerminal", "internalConsoleOptions": "neverOpen", "serverReadyAction": { "action": "openExternally", "pattern": "\\bNow listening on:\\s+(https?://\\S+)" }, "env": { "ASPNETCORE_ENVIRONMENT": "Development" }, "sourceFileMap": { "/Views": "${workspaceFolder}/Views" } }, { "name": ".NET Core Launch (webapi_identity_server)", "type": "coreclr", "request": "launch", "preLaunchTask": "build_webapi_identity_server", "program": "${workspaceFolder}/Test_WebAPI_IdentityServer/bin/Debug/net5.0/Test_WebAPI_IdentityServer.dll", "args": [], "cwd": "${workspaceFolder}/Test_WebAPI_IdentityServer", "stopAtEntry": false, "console": "integratedTerminal", "internalConsoleOptions": "neverOpen", "serverReadyAction": { "action": "openExternally", "pattern": "\\bNow listening on:\\s+(https?://\\S+)" }, "env": { "ASPNETCORE_ENVIRONMENT": "Development" }, "sourceFileMap": { "/Views": "${workspaceFolder}/Views" } }, { "name": ".NET Core Launch (webapi_client)", "type": "coreclr", "request": "launch", "preLaunchTask": "build_webapi_client", "program": "${workspaceFolder}/Test_WebAPI_Client/bin/Debug/net5.0/Test_WebAPI_Client.dll", "args": [], "cwd": "${workspaceFolder}/Test_WebAPI_Client", "stopAtEntry": false, "console": "integratedTerminal", "internalConsoleOptions": "neverOpen", "serverReadyAction": { "action": "openExternally", "pattern": "\\bNow listening on:\\s+(https?://\\S+)" }, "env": { "ASPNETCORE_ENVIRONMENT": "Development" }, "sourceFileMap": { "/Views": "${workspaceFolder}/Views" } } ], //多项目同时调试 "compounds": [ { "name": "WebAPI_Server/WebAPI_Client", "configurations": [ ".NET Core Launch (webapi_server)", ".NET Core Launch (webapi_identity_server)" ], "preLaunchTask": "clean_build" //预执行Task(如清理项目等) }, { "name": "gRPC_Server/gRPC_Client", "configurations": [ ".NET Core Launch (grpc_server)", ".NET Core Launch (grpc_client)" ], "preLaunchTask": "clean_build" //预执行Task(如清理项目等) } ] }
2、粘贴下面内容到xxx\.vscode\tasks.json
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "clean_build", "type": "shell", "command": "./clean.ps1", //多个命令用";"隔开 "args": [ "param1", "param2" ], "group": { "kind": "build", "isDefault": true //为true 时,可以通过Ctrl+Shift+B直接运行编译任务 } }, { "label": "build", "command": "dotnet", "type": "process", "args": [ "build", "${workspaceFolder}/Test", //多个项目时去掉这儿的路径,调试时选择项目即可 "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], "problemMatcher": "$msCompile", "presentation": { "panel": "new" } }, { "label": "build_grpc_server", "command": "dotnet", "type": "process", "args": [ "build", "${workspaceFolder}/Test_gRPC_Server", //多个项目时去掉这儿的路径,调试时选择项目即可 "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], "problemMatcher": "$msCompile", "presentation": { "panel": "new" } }, { "label": "build_grpc_client", "command": "dotnet", "type": "process", "args": [ "build", "${workspaceFolder}/Test_gRPC_Client", //多个项目时去掉这儿的路径,调试时选择项目即可 "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], "problemMatcher": "$msCompile", "presentation": { "panel": "new" } }, { "label": "build_webapi_server", "command": "dotnet", "type": "process", "args": [ "build", "${workspaceFolder}/Test_WebAPI_Server", //多个项目时去掉这儿的路径,调试时选择项目即可 "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], "problemMatcher": "$msCompile", "presentation": { "panel": "new" } }, { "label": "build_webapi_identity_server", "command": "dotnet", "type": "process", "args": [ "build", "${workspaceFolder}/Test_WebAPI_IdentityServer", //多个项目时去掉这儿的路径,调试时选择项目即可 "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], "problemMatcher": "$msCompile", "presentation": { "panel": "new" } }, { "label": "build_webapi_client", "command": "dotnet", "type": "process", "args": [ "build", "${workspaceFolder}/Test_WebAPI_Client", //多个项目时去掉这儿的路径,调试时选择项目即可 "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], "problemMatcher": "$msCompile", "presentation": { "panel": "new" } }, { "label": "publish", "command": "dotnet", "type": "process", "args": [ "publish", "${workspaceFolder}", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], "problemMatcher": "$msCompile", "presentation": { "panel": "new" } }, { "label": "watch", "command": "dotnet", "type": "process", "args": [ "watch", "run", "${workspaceFolder}", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], "problemMatcher": "$msCompile", "presentation": { "panel": "new" } } ] }
五、检查更新报错 net::ERR_CERT_AUTHORITY_INVALID
解决办法:快捷方式 启动参数 增加:--ignore-certificate-errors