Visual Studio Code Cmd



In Visual Studio Code, you can open an integrated terminal, initially starting at the root of your workspace. This can be convenient as you don't have to switch windows or alter the state of an existing terminal to perform a quick command-line task. To open the terminal: Use the ⌃` (Windows, Linux Ctrl+`) keyboard shortcut with the backtick character.

Extension for Visual Studio Code - This extension allows you to remotely control Visual Studio Code. Run commands from anywhere you want on your device. The extension allows you to take VSCode automation to the next level. With rustup missing, you won’t be able to get the Rust Language Server (RLS) up and running in Visual Studio Code. When you click on the button, your browser will download the rustup-init.exe executable, which is essentially a command-line installer. Proceed along with the. Visual Studio Code 1.55.1: 22181: Friday, April 9, 2021: Approved: Visual Studio Code 1.55.0: 27609: Wednesday, March 31, 2021: Approved: Visual Studio Code 1.54.3: 50831: Tuesday, March 16, 2021: Approved: Visual Studio Code 1.54.2: 21260: Friday, March 12, 2021: Approved: Visual Studio Code 1.54.1: 28846: Friday, March 5, 2021: Approved: Visual Studio Code 1.54.0: 5691.

-->

Visual Studio Code, along with the Remote - WSL extension, enables you to use WSL as your full-time development environment directly from VS Code. You can:

  • develop in a Linux-based environment
  • use Linux-specific toolchains and utilities
  • run and debug your Linux-based applications from the comfort of Windows while maintaining access to productivity tools like Outlook and Office
  • use the VS Code built-in terminal to run your Linux distribution of choice
  • take advantage of VS Code features like Intellisense code completion, linting, debug support, code snippets, and unit testing
  • easily manage your version control with VS Code's built-in Git support
  • run commands and VS Code extensions directly on your WSL projects
  • edit files in your Linux or mounted Windows filesystem (for example /mnt/c) without worrying about pathing issues, binary compatibility, or other cross-OS challenges

Install VS Code and the Remote WSL extension

  • Visit the VS Code install page and select the 32 or 64 bit installer. Install Visual Studio Code on Windows (not in your WSL file system).

  • When prompted to Select Additional Tasks during installation, be sure to check the Add to PATH option so you can easily open a folder in WSL using the code command.

  • Install the Remote Development extension pack. This extension pack includes the Remote - WSL extension, in addition to the Remote - SSH, and Remote - Containers extensions, enabling you to open any folder in a container, on a remote machine, or in WSL.

Important

In order to install the Remote-WSL extension, you will need the 1.35 May release version or later of VS Code. We do not recommend using WSL in VS Code without the Remote-WSL extension as you will lose support for auto-complete, debugging, linting, etc. Fun fact: this WSL extension is installed in $HOME/.vscode/extensions (enter the command ls $HOME.vscodeextensions in PowerShell).

Update your Linux distribution

Some WSL Linux distributions are lacking libraries that are required by the VS Code server to start up. You can add additional libraries into your Linux distribution by using its package manager.

For example, to update Debian or Ubuntu, use:

To add wget (to retrieve content from web servers) and ca-certificates (to allow SSL-based applications to check for the authenticity of SSL connections), enter:

Open a WSL project in Visual Studio Code

From the command-line

To open a project from your WSL distribution, open the distribution's command line and enter: code .

From VS Code

You can also access more VS Code Remote options by using the shortcut: CTRL+SHIFT+P in VS Code to bring up the command palette. If you then type Remote-WSL you will see a list of the VS Code Remote options available, allowing you to reopen the folder in a remote session, specify which distribution you want to open in, and more.

Extensions inside of VS Code Remote

The Remote-WSL extension splits VS Code into a “client-server” architecture, with the client (the user interface) running on your Windows machine and the server (your code, Git, plugins, etc) running remotely.

When running VS Code Remote, selecting the 'Extensions' tab will display a list of extensions split between your local machine and your WSL distribution.

Visual studio code vs microsoft visual studio

Installing a local extension, like a theme, only needs to be installed once.

Some extensions, like the Python extension or anything that handles things like linting or debugging, must be installed separately on each remote WSL distributions. VS Code will display a warning icon ⚠, along with a green 'Install in WSL' button, if you have an extension locally installed that is not installed on your WSL Remote.

For further information, see the VS Code docs:

Visual studio code command shortcut
  • When VS Code Remote is started in WSL, no shell startup scripts are run. See this advanced environment setup script article for more info on how to run additional commands or modify the environment.

  • Having problems launching VS Code from your WSL command line? This troubleshooting guide includes tips on changing path variables, resolving extension errors about missing dependencies, resolving Git line ending issues, installing a local VSIX on a remote machine, launching a browser window, blocker localhost port, web sockets not working, errors storing extension data, and more.

Install Git (optional)

If you plan to collaborate with others, or host your project on an open-source site (like GitHub), VS Code supports version control with Git. The Source Control tab in VS Code tracks all of your changes and has common Git commands (add, commit, push, pull) built right into the UI.

To install Git, see set up Git to work with Windows Subsystem for Linux.

Install Windows Terminal (optional)

The new Windows Terminal enables multiple tabs (quickly switch between Command Prompt, PowerShell, or multiple Linux distributions), custom key bindings (create your own shortcut keys for opening or closing tabs, copy+paste, etc.), emojis ☺, and custom themes (color schemes, font styles and sizes, background image/blur/transparency). Learn more in the Windows Terminal docs.

Code
  1. Get Windows Terminal in the Microsoft Store: By installing via the store, updates are handled automatically.

  2. Once installed, open Windows Terminal and select Settings to customize your terminal using the profile.json file.

Additional Resources

A few additional extensions you may want to consider include:

  • Keymaps from other editors: These extensions can help your environment feel right at home if you're transitioning from another text editor (like Atom, Sublime, Vim, eMacs, Notepad++, etc).
  • Settings Sync: Enables you to synchronize your VS Code settings across different installations using GitHub. If you work on different machines, this helps keep your environment consistent across them.
  • Debugger for Chrome: Once you finish developing on the server side with Linux, you'll need to develop and test the client side. This extension integrates your VS Code editor with your Chrome browser debugging service, making things a bit more efficient.
-->

Applies to: SQL Server (all supported versions) - Linux

This article shows how to use the mssql extension for Visual Studio Code to develop SQL Server databases. Because Visual Studio Code is cross-platform, you can use mssql extension on Linux, macOS, and Windows.

Install and start Visual Studio Code

Visual Studio Code is a cross-platform, graphical code editor that supports extensions.

  1. Download and install Visual Studio Code on your machine.

  2. Start Visual Studio Code.

    Note

    If Visual Studio Code does not start when you are connected through an xrdp remote desktop session, see VS Code not working on Ubuntu when connected using XRDP.

Install the mssql extension

The mssql extension for Visual Studio Code lets you connect to a SQL Server, query with Transact-SQL (T-SQL), and view the results.

  1. In Visual Studio Code, select View > Command Palette, or press Ctrl+Shift+P, or press F1 to open the Command Palette.

  2. In the Command Palette, select Extensions: Install Extensions from the dropdown.

  3. In the Extensions pane, type mssql.

  4. Select the SQL Server (mssql) extension, and then select Install.

  5. After the installation completes, select Reload to enable the extension.

Create or open a SQL file

The mssql extension enables mssql commands and T-SQL IntelliSense in the code editor when the language mode is set to SQL.

  1. Select File > New File or press Ctrl+N. Visual Studio Code opens a new Plain Text file by default.

  2. Select Plain Text on the lower status bar, or press Ctrl+K > M, and select SQL from the languages dropdown.

    Note

    If this is the first time you have used the extension, the extension installs supporting SQL Server tools.

If you open an existing file that has a .sql file extension, the language mode is automatically set to SQL.

Connect to SQL Server

Follow these steps to create a connection profile and connect to a SQL Server.

Visual Studio Code Cmd

  1. Press Ctrl+Shift+P or F1 to open the Command Palette.

  2. Type sql to display the mssql commands, or type sqlcon, and then select MS SQL: Connect from the dropdown.

    Note

    A SQL file, such as the empty SQL file you created, must have focus in the code editor before you can execute the mssql commands.

  3. Select the MS SQL: Manage Connection Profiles command.

  4. Then select Create to create a new connection profile for your SQL Server.

  5. Follow the prompts to specify the properties for the new connection profile. After specifying each value, press Enter to continue.

    Connection propertyDescription
    Server name or ADO connection stringSpecify the SQL Server instance name. Use localhost to connect to a SQL Server instance on your local machine. To connect to a remote SQL Server, enter the name of the target SQL Server, or its IP address. To connect to a SQL Server container, specify the IP address of the container's host machine. If you need to specify a port, use a comma to separate it from the name. For example, for a server listening on port 1401, enter <servername or IP>,1401.
    As an alternative, you can enter the ADO connection string for your database here.
    Database name (optional)The database that you want to use. To connect to the default database, don't specify a database name here.
    Authentication TypeChoose either Integrated or SQL Login.
    User nameIf you selected SQL Login, enter the name of a user with access to a database on the server.
    PasswordEnter the password for the specified user.
    Save PasswordPress Enter to select Yes and save the password. Select No to be prompted for the password each time the connection profile is used.
    Profile Name (optional)Type a name for the connection profile, such as localhost profile.

    After you enter all values and select Enter, Visual Studio Code creates the connection profile and connects to the SQL Server.

    Tip

    If the connection fails, try to diagnose the problem from the error message in the Output panel in Visual Studio Code. To open the Output panel, select View > Output. Also review the connection troubleshooting recommendations.

  6. Verify your connection in the lower status bar.

As an alternative to the previous steps, you can also create and edit connection profiles in the User Settings file (settings.json). To open the settings file, select File > Preferences > Settings. For more information, see Manage connection profiles.

Create a SQL database

  1. In the new SQL file that you started earlier, type sql to display a list of editable code snippets.

  2. Select sqlCreateDatabase.

  3. In the snippet, type TutorialDB to replace 'DatabaseName':

  4. Press Ctrl+Shift+E to execute the Transact-SQL commands. View the results in the query window.

    Tip

    You can customize the shortcut keys for the mssql commands. See Customize shortcuts.

Create a table

  1. Delete the contents of the code editor window.

  2. Press Ctrl+Shift+P or F1 to open the Command Palette.

  3. Type sql to display the mssql commands, or type sqluse, and then select the MS SQL: Use Database command.

  4. Select the new TutorialDB database.

  5. In the code editor, type sql to display the snippets, select sqlCreateTable, and then press Enter.

  6. In the snippet, type Employees for the table name.

  7. Press Tab to get to the next field, and then type dbo for the schema name.

  8. Replace the column definitions with the following columns:

  9. Press Ctrl+Shift+E to create the table.

Insert and query

  1. Add the following statements to insert four rows into the Employees table.

    While you type, T-SQL IntelliSense helps you to complete the statements:

    Tip

    The mssql extension also has commands to help create INSERT and SELECT statements. These were not used in the previous example.

  2. Press Ctrl+Shift+E to execute the commands. The two result sets display in the Results window.

View and save the result

  1. Select View > Editor Layout > Flip Layout to switch to a vertical or horizontal split layout.

  2. Select the Results and Messages panel headers to collapse and expand the panels.

    Tip

    You can customize the default behavior of the mssql extension. See Customize extension options.

  3. Select the maximize grid icon on the second result grid to zoom in to those results.

    Note

    The maximize icon displays when your T-SQL script produces two or more result grids.

  4. Open the grid context menu by right-clicking on the grid.

  5. Select Select All.

  6. Open the grid context menu again and select Save as JSON to save the result to a .json file.

  7. Specify a file name for the JSON file.

  8. Verify that the JSON file saves and opens in Visual Studio Code.

Visual Studio Code Cmd Command

If you need to save and run SQL scripts later, for administration or a larger development project, save the scripts with a .sql extension.

Next steps

If you're new to T-SQL, see Tutorial: Write Transact-SQL statements and the Transact-SQL Reference (Database Engine).

Visual Studio Code Command Shortcut

For more information on using or contributing to the mssql extension, see the mssql extension project wiki.

For more information on using Visual Studio Code, see the Visual Studio Code documentation.