VS Code Command Line 给出的启动路径指令不正确;示例中显示的前导冒号不起作用。但是,以反斜杠结尾的目录名称启动会按预期打开指定的目录。
例如,
代码 C:\Users\DAVE\Documents\Programming\Angular\StringCalculator\src\
在目录 C:\Users\DAVE\Documents\Programming\Angular\StringCalculator\src 中打开 Visual Studio Code 编辑器。
重要提示: 终端反斜杠虽然是可选的,但很有用,因为它清楚地表明打算打开一个目录,而不是文件。请记住,文件名扩展名一直是可选的。
注意:附加到 PATH 列表的目录是 \bin 目录,而 shell 命令 code 会启动 Windows NT 命令脚本。
因此,当您希望脚本的其余部分运行时,code 必须被调用或启动合并到另一个 shell 脚本中。幸运的是,我在第一次测试新的 shell 脚本之前发现了这一点,我正在创建该脚本以在本地 Web 服务器、我的默认 Web 浏览器和 Visual Studio Code 中同时启动一个 Angular 2 项目。
以下是我的 Angular 启动脚本,用于消除对我在其他地方发布但并非严格要求的系统实用程序之一的依赖。
@echo off
转到跳过
=========================================================================
Name: StartAngularApp.CMD
Synopsis: Start the Angular 2 application installed in a specified
directory.
Arguments: %1 = OPTIONAL: Name of directory in which to application
is installed
Remarks: If no argument is specified, the application must be in
the current working directory.
This is a completely generalized Windows NT command
script (shell script) that uses the NPM Angular CLI to
load an Angular 2 application into a Node development
Web server, the default Web browser, and the Visual
Studio Code text editor.
Dependencies: Unless otherwise specified in the command line, the
application is created in the current working directory.
All of the following shell scripts and programs must be
installed in a directory that is on the Windows PATH
directory list.
1) ShowTime.CMD
2) WWPause.exe
3) WWSleep.exe
4) npm (the Node Package Manager) and its startup
script, npm.cmd, must be accessible via the Windows
PATH environment string. By default, this goes into
directory C:\Program Files\nodejs.
5) The Angular 2 startup script, ng.cmd, and the Node
Modules library must be installed for global access.
By default, these go into directory %AppData%\npm.
Author: David A. Gray
Created: Monday, 23 April 2017
-----------------------------------------------------------------------
Revision History
-----------------------------------------------------------------------
Date By Synopsis
---------- --- --------------------------------------------------------
2017/04/23 DAG Script created, tested, and deployed.
=======================================================================
:跳过
echo BOJ %~0, version %~t0
echo.
echo -------------------------------------------------------
echo Displaying the current node.js version:
echo -------------------------------------------------------
echo.
node -v
echo.
echo -------------------------------------------------------
echo Displaying the current Node Package Manager version:
echo -------------------------------------------------------
echo.
call npm -v
echo.
echo -------------------------------------------------------
echo Loading Angular starter application %1
echo into a local Web server, the default Web browser, and
echo the Visual Studio Code text editor.
echo -------------------------------------------------------
echo.
if "%1" neq "" (
echo.
echo -------------------------------------------------------
echo Starting the Angular application in directory %1
echo -------------------------------------------------------
echo.
cd "%~1"
call code %1\src\
) else (
echo.
echo -------------------------------------------------------
echo Starting the Angular application in directory %CD%
echo -------------------------------------------------------
echo.
call code %CD%\src\
)
call ng serve --open
echo.
echo -------------------------------------------------------
echo %~nx0 Done!
echo -------------------------------------------------------
echo.
Pause