网上百度到的大部分都是一步一步根据提示运行,我们可以根据他们的教程一步一步运行完成,参考如何创建.net core app程序https://www.cnblogs.com/jixiaosa/archive/2019/03/01/10457588.html,但是等你创建完了,纳尼???????是不是有很多的小问号。如果你的目录不是工作目录,那么你的配置文件就要手动生成。
vs code中使用模板生成的代码中没有args中第二行中指定的.csproj后缀的文件名称,此处文件名称需要手工指定到工作目录下的相对文件地址。千万不要忽略掉英文提示的地方,那里是需要手工输入的。
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "shell",
"args": [
"build",
// Ask dotnet build to generate full paths for file names.
"MLTest/MLTest.csproj",
"/property:GenerateFullPaths=true",
// Do not generate summary otherwise it leads to duplicate errors in Problems panel
"/consoleloggerparameters:NoSummary"
],
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
}
]
然后,继续运行你就会发现运行成功了,但是无法找到运行dll文件,所以这里也是需要修改它的模板的地址的:参考:这里configurations:里面的program就是我修改过的,它需要指定到具体的生成目录的生成文件。${workspace}这个参数,如果你不修改系统设置的话,它默认就指定了你当前最外层的工作文件夹,所以老老实实的将上面生成成功的文件地址填进去就可以成功运行了。
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: 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}/MLTest/bin/Debug/netcoreapp3.0/MLTest.dll",
"args": [],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
我的目录结构是这个样子的:供参考:
最后结果: