gpt4 book ai didi

c# - 当我尝试启动 C# 代码时,收到消息 '' 找不到任务 'build'

转载 作者:行者123 更新时间:2023-12-02 04:02:29 26 4
gpt4 key购买 nike

我是 C# 新手,正在使用pluralsight 进行学习

我完全按照教程进行操作,但遇到了教程没有的问题。

当您通过 .Net 编写 C# 代码时,我构建了简单的“Hello World”程序

在 Visual Studio Code 中,如果选择“开始调试”或“开始但不调试”,则会弹出以下错误

“找不到任务‘构建’”

然后我还是单击“调试”,然后出现以下错误

启动:程序目录\<在此处插入项目名称>.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 中,加载代码库后。调出command pallet并输入> .NET Generate Assets for Build and Debug然后按回车键。

这将强制 VS Code 重新创建 launch.jsontask.json文件。

请注意 VS Code 窗口的左下角是否有类似如下的 Toast 消息:

screenshot of VS Code showing a toast message asking for confirmation when recreating build and debug assets

并确保单击 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 名称的字符串。

关于c# - 当我尝试启动 C# 代码时,收到消息 '' 找不到任务 'build',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56893702/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com