且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Visual Studio 代码中的launch.json 和task.json 有什么区别?

更新时间:2022-02-23 08:13:45

它们并不都用于设置构建配置.

They are not both used to setup the build configuration.

launch.json 用于启动应用程序进行调试.它的设置适用于映射到您的工作区源代码或定义要使用的 Chrome 端口等.

launch.json is used for to launch an app for debugging. It has settings geared for things like mapping to your workspace source code or defining the Chrome port to use.

要使用 launch.json 中的配置,请在调试"面板上选择它并单击运行按钮.

To use a configuration from launch.json, you select it on the Debug panel and click the run button.

tasks.json 用于执行您可能想要的任何其他内容,例如源代码格式化程序、打包程序或 SASS 编译器.

tasks.json is used to execute anything else you may want, be that source code formatters, bundlers or a SASS compiler.

要使用 tasks.json 中的配置,请从命令列表中选择运行任务".

To use a configuration from tasks.json, you select Run Task from the command list.

以下是它们在用途上有何不同的示例:

我有一个连接到 .NET Web 服务的 Angular 5 应用程序.

I have an Angular 5 application that connects to a .NET web service.

我将一项任务配置为运行 Web 服务,使用的命令可以启动 IISExpress.我有另一个任务配置为使用 ng serve 运行 Angular 应用程序,它会在文件更改时重新编译应用程序.每当我重新打开 VS Code 或 Web 服务发生变化时,我都会执行这两个任务.

I have one task configured to run the web service, using a command that fires up IISExpress. I have another task configured to run the Angular app using ng serve, which recompiles the app when files change. I execute these two tasks whenever I reopen VS Code, or when the web service changes.

我也有两种启动配置:一种用于启动 Chrome 并启动调试器,另一种用于调试 Chrome 中已加载的页面.每当我开始调试会话时,我都会执行这些.

I have two launch configurations as well: One to launch Chrome and start the debugger, and another to debug a page already loaded in Chrome. These I execute whenever I start a debug session.