文档中提到了一种叫做代码的可执行文件,但我不确定在哪里可以找到它,所以我可以把它放在我的路径上。我从VSCode网站下载的zip文件不包括任何这样的可执行文件。(我可以很好地运行.app。)

这是windows独有的功能吗?


当前回答

我把这个添加到我的~/.profile中

alias vscode='/Applications/Visual\ Studio\ Code.app/Contents/MacOS/Electron'

then

. ~/.profile

之后我就可以做了

 vscode

从终点站

其他回答

在VS Code命令行中给出的启动路径的指令是不正确的;示例中显示的前导冒号不起作用。但是,以反斜杠结束的目录名启动将按预期打开指定的目录。

举个例子,

代码C:\Users\DAVE\Documents\编程\角\ StringCalculator \ src \

在C:\Users\DAVE\Documents\Programming\Angular\StringCalculator\src目录下打开Visual Studio代码编辑器。

重要提示:终端反斜杠虽然是可选的,但很有用,因为它清楚地表明意图是打开一个目录,而不是打开一个文件。请记住,文件扩展名一直都是可选的。

注意:附加到PATH列表的目录是\bin目录,shell命令代码启动Windows NT command脚本。

因此,当合并到另一个shell脚本中时,如果您希望运行脚本的其余部分,则必须调用或启动代码。值得庆幸的是,在我第一次测试一个新的shell脚本之前,我发现了这一点。我创建这个脚本是为了在本地Web服务器、默认的Web浏览器和Visual Studio Code中同时启动一个Angular 2项目。

下面是我的Angular启动脚本,经过调整,消除了对某个发布在其他地方的系统实用程序的依赖,但不是严格要求的。


@echo off

goto SKIPREM

=========================================================================

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

运行代码的步骤。命令启动VSCode应用程序-

打开VSCode 打开命令托盘(Cmd+Shift+P) 输入Shell命令:在PATH中安装'code'命令并选择 你会得到Shell命令'code'成功安装在PATH的通知。 重新启动终端并输入代码。 这将从其中的当前文件夹文件打开VSCode。

在我的情况下,我必须使用一个别名:

alias code="/<PATH TO VSCODE>/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code"

您可以在~/.bash_profile中添加这个别名。

我把这个添加到我的~/.profile中

alias vscode='/Applications/Visual\ Studio\ Code.app/Contents/MacOS/Electron'

then

. ~/.profile

之后我就可以做了

 vscode

从终点站

从Visual Studio代码设置页面:

Tip: If you want to run VS Code from the terminal by simply typing 'code', VS Code has a command, Shell Command: Install 'code' command in PATH, to add 'code' to your $PATH variable list. After installation, launch VS Code. Now open the Command Palette (F1 or ⇧+⌘+P on Mac) and type shell command to find the Shell Command: Install 'code' command in PATH command. After executing the command, restart the terminal for the new $PATH value to take effect. You'll be able to simply type 'code .' in any folder to start editing files in that folder.