如何在VS Code中指定启动项目? [英] How do I designate a startup project in VS Code?
问题描述
如何在VS Code中指定启动项目?
How do I designate a startup project in VS Code?
上下文:
在Visual Studio中,我右键单击解决方案资源管理器中的一个项目并将其设置为启动.
In Visual Studio, I right click a project within solution explorer and set it as startup.
但是,我不清楚如何在VS Code中完成此操作.
However, I am not clear on how to accomplish this in VS Code.
注意:
我最近在VS Code中将一个WebAPI项目添加到了我的目录中.
I recently added a WebAPI project to my directory in VS Code.
推荐答案
这也许值得一个更好的答案.所以让我解释一下.在Visual Studio Code中,您必须在 launch.json 和 tasks.json 文件中全部设置启动项目.
This maybe deserves a better answer. So let me explain. In Visual Studio Code you have to set up your startup projects all in the launch.json and the tasks.json files.
这是一个详细的简介:
Here is a small detailed introduction:
-
选择一个根项目文件夹(即:D:/anyfolder/myrootfolder)
Choose a root project folder (i.e.: D:/anyfolder/myrootfolder)
在根文件夹中为两个项目创建两个文件夹
2.1 D:/anyfolder/myrootfolder/project1
2.2 D:/anyfolder/myrootfolder/project2
Create two folders for two projects in the root folder
2.1 D:/anyfolder/myrootfolder/project1
2.2 D:/anyfolder/myrootfolder/project2
打开cmd并创建两个控制台应用程序(我使用.netcore 2.0)
3.1使用cmd转到文件夹 project1 和 project2 (命令:cd -foldername-)
3.2对于每个文件夹执行以下命令: dotnet新控制台
Open cmd and create two Console-Applications (I use .netcore 2.0)
3.1 go to folders project1 and project2 using cmd (Command: cd -foldername-)
3.2 for each of that folders execute the command: dotnet new console
使用Visual Studio代码
Open the root project folder with Visual Studio Code
将以下 launch.json 和 tasks.json 添加到.vscode文件夹(通常是在单击VS代码)
有关更多信息,请访问: https://code.visualstudio.com/docs/editor/debugging
Add the following launch.json and tasks.json to the .vscode folder (usually the .vscode folder is generated after clicked the debug-button in VS Code)
For More information visit:https://code.visualstudio.com/docs/editor/debugging
样本 launch.json 文件:
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch Project1",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/project1/bin/Debug/netcoreapp2.0/project1.dll",
"args": [],
"cwd": "${workspaceRoot}/project1",
"stopAtEntry": false,
"console": "internalConsole"
},
{
"name": ".NET Core Launch Project2",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/project2/bin/Debug/netcoreapp2.0/project2.dll",
"args": [],
"cwd": "${workspaceRoot}/project2",
"stopAtEntry": false,
"console": "internalConsole"
}
]
}
样本 tasks.json 文件:
{
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [
"${workspaceRoot}/project1/project1.csproj"
],
"isBuildCommand": true,
"problemMatcher": "$msCompile"
},
{
"taskName": "build",
"args": [
"${workspaceRoot}/project2/project2.csproj"
],
"isBuildCommand": true,
"problemMatcher": "$msCompile"
}
]
}
别忘了我使用了 .netcore 2.0 .如果使用其他目标框架,则必须自定义上面的示例文件.
Don't forget that I used .netcore 2.0. If you use another Target Framework you have to customize the upper sample files of course.
毕竟,您现在应该在Play(Debug-)按钮的右侧看到两个项目:
.NET Core启动项目1 和
.NET Core启动项目2
After all you should now see two items in right of the Play(Debug-)button:
.NET Core Launch Project1 and
.NET Core Launch Project2
这对我和我的目的都有用...
This worked for me and my purposes...
这篇关于如何在VS Code中指定启动项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!