我使用以下命令创建了一个新的.NET Core应用程序:
dotnet new console -o test
Run Code Online (Sandbox Code Playgroud)
当我尝试在Visual Studio代码调试器中运行它时,我得到:
Could not find the preLaunchTask 'build'?
Run Code Online (Sandbox Code Playgroud)
Visual Studio Code为我生成了这些文件:
tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [ ],
"isBuildCommand": true,
"showOutput": "silent",
"problemMatcher": "$msCompile"
}
]
}
Run Code Online (Sandbox Code Playgroud)
和
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/<target-framework>/<project-name.dll>",
"args": [],
"cwd": …Run Code Online (Sandbox Code Playgroud) 将我的 .NET Core 项目移至解决方案中的子文件夹后,我无法再使用 VS Code 对其进行调试。
如果我移动tasks.json到launch.json项目文件夹并打开 VS Code,我就可以进行调试,但我希望能够在 VS Code 中打开整个解决方案。
我收到的错误消息是这样的:
MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.
该错误似乎表明我的任务运行程序无法再找到我的项目,因此我尝试将其添加到tasks.json:
{
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [ ],
"isBuildCommand": true,
"showOutput": "silent",
"problemMatcher": "$msCompile"
}
],
// My addition
"options": {
"cwd": "${workspaceRoot}/myProjectFolder"
}
}
Run Code Online (Sandbox Code Playgroud)
这样做我可以启动任务,但随后出现以下错误:
Exception thrown: …Run Code Online (Sandbox Code Playgroud)