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

这是windows独有的功能吗?


当前回答

在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

其他回答

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

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

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

在OSX Mavericks上,我在~/bin中创建了一个名为vscode的bash脚本(改编自vscode Setup中的.bashrc):

#!/bin/bash

if [[ $# = 0 ]]
then
    open -a "Visual Studio Code"
else
    [[ $1 = /* ]] && F="$1" || F="$PWD/${1#./}"
    open -a "Visual Studio Code" --args "$F"
fi

Vscode <文件或目录>现在按预期工作。

我们将脚本更新为以下语法,以支持多个文件和文件夹作为参数,并修复了无法正确检测当前工作目录的问题:

code () {
    VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $*
}

VS Code 1.0版本更新:

请从命令面板(查看|命令面板)使用命令在路径中安装“代码”命令或在路径中安装“代码内部人员”命令,使代码可用于命令行。

在打开VSC并按下(Command + Up + P)后,我尝试输入“shell Command”,但什么都没有出现。为了得到“Shell Command: Install 'code' Command In PATH Command”,你必须执行以下命令:

按(Command, Up, P) 输入>(这将显示并运行命令) 然后在PATH命令中输入Shell命令:Install 'code'命令。然后它就会出现。 一旦你点击它,它会更新,你应该很好!

从命令行文档启动MacOS X

链接你当前的文件夹到vscode。

Windows Registry Editor Version 5.00

; Directory\Background\shell => on empty space

[HKEY_CLASSES_ROOT\Directory\Background\shell\vscode]
"Icon"="C:\\current-folder-vscode\\Code.exe,0"
@="VsCode"

[HKEY_CLASSES_ROOT\Directory\Background\shell\vscode\command]
@="C:\\current-folder-vscode\\Code.exe ."

; Directory\shell => on a folder

[HKEY_CLASSES_ROOT\Directory\shell\vscode]
@="VsCode"
"Icon"="C:\\current-folder-vscode\\Code.exe,0"

[HKEY_CLASSES_ROOT\Directory\shell\vscode\command]
@="C:\\current-folder-vscode\\Code.exe ."