Transitioning from Visual Studio to Visual Studio Code: A Practical Guide for Developers

Transitioning from Visual Studio to Visual Studio Code: A Practical Guide for Developers

Introduction

Suppose you’re an experienced Visual Studio user transitioning to Visual Studio Code (VS Code). In that case, this post will help you understand how to perform common tasks in VS Code that you’re familiar with in Visual Studio.

Opening and Organizing Files

Visual Studio:

  • Projects and solutions are the main ways to organize code.

Visual Studio Code:

  • You can open files directly without needing a project or solution file.
  • Use File > Open File... to open individual files.
  • Use File > Open Folder... to work on entire directories of code, similar to opening a project.
  • The Explorer pane (shortcut: Ctrl+Shift+E) in VS Code is analogous to Solution Explorer in Visual Studio.

Editing Files

Visual Studio:

  • Robust IntelliSense, code refactoring tools, and shortcuts.

Visual Studio Code:

  • IntelliSense works out of the box for many languages, providing intelligent code completion.
  • Access additional editing features by installing extensions for specific languages or frameworks.
  • VS Code supports a variety of keyboard shortcuts. Customize them in File > Preferences > Keyboard Shortcuts.

Searching and Replacing

Visual Studio:

  • Search is typically project or solution-wide.

Visual Studio Code:

  • Use Ctrl+P to quickly search and open files.
  • For in-file search, use Ctrl+F and Ctrl+H for find and replace.
  • For a global search across all files, use the Search sidebar (Ctrl+Shift+F).
  • Regular expressions and case-sensitive searches are also supported in these search functionalities.

Source Control and Git Integration

Visual Studio:

  • Integrated source control support, particularly for Git.

Visual Studio Code:

  • Built-in Git integration. Access most Git commands via the Source Control pane (Ctrl+Shift+G).
  • Stage changes, commit, pull, and push directly from the GUI.
  • For more advanced Git operations, open the integrated terminal (Ctrl+ `) and use Git commands as you would in the command line.

Basic Git Operations in VS Code

Initializing a Repository:
You can initialize a Git repository for your project directly in VS Code by opening the command palette (Ctrl+Shift+P), then typing and selecting Git: Initialize Repository. This creates a new Git repository in your current project folder.

Cloning an Existing Repository:
Clone a repository by opening the command palette and selecting Git: Clone. Enter the repository URL, and VS Code will clone it into a specified directory.

Committing Changes:
The Source Control panel (Ctrl+Shift+G) lists all your changed files. Stage your changes by clicking the + button next to each file or right-click and select Stage Changes.

Once changes are staged, commit them by typing a commit message in the message box and pressing Ctrl+Enter.

Pushing and Pulling Changes:
Push your changes to the remote repository using the ... button in the Source Control panel and selecting Push.

Similarly, to update your local repository with changes from the remote, use the Pull command from the same menu.

Branching:
Create, delete, and switch branches through the Source Control panel. The current branch is displayed at the bottom left corner of the VS Code window, and clicking on it will show a list of all branches. You can create a new branch from here as well.

Merge Conflicts:
VS Code provides an intuitive interface for resolving merge conflicts. It highlights conflicts directly in the code editor, allowing you to choose between incoming or current changes, or to merge them manually.

Advanced Git Features

GitLens Extension: Enhances the built-in Git capabilities of VS Code. It offers advanced blame information, file history, commit searching, and much more.

Integrated Terminal for Git Commands: Some complex Git operations might not have a direct GUI in VS Code. For these, the integrated terminal (Ctrl+ `) is invaluable. You can run any Git command as you would in a standard terminal.

Using Git with Integrated Development Environment (IDE) Features

Debugging with Git: You can switch branches and instantly see the effect on your code within the editor. This is particularly useful for testing different versions or branches of your code.

Code Comparison: Easily compare changes across different commits or branches using the built-in diff tool in VS Code.

Extensions for Workflow Enhancement: Various extensions integrate with Git to provide additional functionalities like continuous integration, code quality checks, or automated builds and deployments.

Debugging

Visual Studio:

  • Powerful debugging tools integrated into the IDE.

Visual Studio Code:

  • VS Code has configurable debugging capabilities, accessible from the Run and Debug sidebar (Ctrl+Shift+D).
  • You can create launch.json configurations for different debug scenarios.
  • Extensions like “C# for Visual Studio Code” can provide additional debugging support specific to your language or framework.

Extensions and Customization

Visual Studio:

  • Offers a range of extensions and customization options.

Visual Studio Code:

  • The Extensions view (Ctrl+Shift+X) allows you to browse and install extensions. This can replicate or extend the functionalities you’re used to in Visual Studio.
  • Customize your settings in File > Preferences > Settings or by editing the settings.json file directly.

Helpful Tips for Transitioning

  1. Keyboard Shortcuts: Many Visual Studio shortcuts also work in VS Code. You can also install the “Visual Studio Keymap” extension for a more familiar shortcut experience.
  2. User Interface Familiarization: Spend some time exploring the VS Code interface. It’s more modular and customizable than Visual Studio.
  3. Extensions Are Key: The functionality of VS Code is greatly enhanced by extensions. Whether it’s language support, linting, or source control, there’s likely an extension available for your needs.
  4. Integrated Terminal: Embrace the integrated terminal in VS Code for running commands, scripts, Git operations, and more, providing a more unified development experience.

By understanding these key aspects of VS Code, a developer experienced with Visual Studio can make a smooth transition and leverage the strengths of VS Code in their development workflow.

Stephen

Hi, my name is Stephen Finchett. I have been a software engineer for over 30 years and worked on complex, business critical, multi-user systems for all of my career. For the last 15 years, I have been concentrating on web based solutions using the Microsoft Stack including ASP.Net, C#, TypeScript, SQL Server and running everything at scale within Kubernetes.