![](/img/trans.png)
[英]C# - when i try play my exe file i get security error message, what can i do?
[英]I get the message ''could not find the task 'build'" when I try to start my C# code
我是 C# 新手,正在學習使用復數
我完全遵循了教程正在做的事情,但遇到了教程沒有的問題。
當您通過 .Net 編寫 C# 代碼時,我構建了簡單的“Hello World”程序
在Visual Studio Code中,如果選擇Start Debugging或Start without Debugging,會彈出如下錯誤
''找不到任務 'build'"
然后我還是點擊調試然后出現以下錯誤
launch:program dir \\ < insert-project-name-here >.dll不存在有打開launch.json的選項
令人困惑的是,.dll 文件確實存在......
此外,檢查launch.json,我有以下內容:
{
// 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": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"WARNING01": "*********************************************************************************",
"WARNING02": "The C# extension was unable to automatically decode projects in the current",
"WARNING03": "workspace to create a runnable launch.json file. A template launch.json file has",
"WARNING04": "been created as a placeholder.",
"WARNING05": "",
"WARNING06": "If OmniSharp is currently unable to load your project, you can attempt to resolve",
"WARNING07": "this by restoring any missing project dependencies (example: run 'dotnet restore')",
"WARNING08": "and by fixing any reported errors from building the projects in your workspace.",
"WARNING09": "If this allows OmniSharp to now load your project then --",
"WARNING10": " * Delete this file",
"WARNING11": " * Open the Visual Studio Code command palette (View->Command Palette)",
"WARNING12": " * run the command: '.NET: Generate Assets for Build and Debug'.",
"WARNING13": "",
"WARNING14": "If your project requires a more complex launch configuration, you may wish to delete",
"WARNING15": "this configuration and pick a different template using the 'Add Configuration...'",
"WARNING16": "button at the bottom of this file.",
"WARNING17": "*********************************************************************************",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/<insert-target-framework-here>/<insert-project-name-here>.dll",
"args": ["link"],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
在 VS Code 中,加載代碼庫后。 調出命令托盤並輸入> .NET Generate Assets for Build and Debug
然后點擊回車/回車。
這將強制 VS Code 重新創建launch.json
和task.json
文件。
留意 VS Code 窗口的左下角是否有一條吐司消息,如下所示:
並確保您單擊Yes
您需要更改task.json
文件中當前讀取的行:
"program": "${workspaceFolder}/bin/Debug/<insert-target-framework-here>/<insert-project-name-here>.dll",
將<insert-target-framework-here>
替換為 csproj 中的目標框架名稱,它可能類似於以下內容:
<TargetFramework>netcoreapp2.1</TargetFramework>
您還需要將<insert-project-name-here>.dll
字符串替換為您生成的 DLL 的名稱。
我有一個類似的問題,傑米泰勒的回答從一開始就沒有為我做,它一直說“找不到任務‘構建’”,我無法評論他的回答,所以這對我有用。
簡答
在調用> .NET Generate Assets for Build and Debug
之前,遞歸地刪除解決方案根目錄中的任何 .vscode 文件夾(如果有)。
長答案
我每次都在 OmniSharp 日志中查找第一個錯誤(在輸出窗格中,OmniSharpLog 下拉列表中):
mkdir C:\\Microsoft\\Xamarin\\NuGet\\
dotnet restore
OmniSharp 日志中不再出現故障,但它仍然抱怨構建任務。 就我而言,我注意到我有兩個 .vscode 文件夾,一個在根目錄,一個在我的解決方案中的另一個文件夾中:
- 刪除了所有這些
- 稱為> .NET Generate Assets for Build and Debug
它成功了,並看到它正確創建了launch.json
和tasks.json
。
現在我可以正確調試了。
這聽起來可能很奇怪,但在我的情況下,當我按 Ctrl + Shift + B更新我的 Visual Studio Code 后,構建操作成功進行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.