Running A Visual Studio 2019 Solution In Visual Studio Code

Introduction

 
In today’s article we will look at how to run an application built in Visual Studio 2019 in Visual Studio Code. Visual Studio Code is a free, open source, lightweight development IDE which can be used across platforms including Windows, Linux, and Mac OS. In the case that we have an application that has already been built using Visual Studio and we want to run this from Visual Studio Code, there are a few steps that need to be done. We will look at these steps in this article.

Downloading Visual Studio Code
 
In case you need to download Visual Studio Code, you can do so from the below URL,
 
https://code.visualstudio.com/download
 
Here you will see the downloads for different operating systems as below,
 
Running A Visual Studio 2019 Solution In Visual Studio Code
 
The Visual Studio Application
 
The Visual Studio application we will be using for this article is a simple console application built using the .NET framework 4.7.2. It has been built using Visual Studio 2019 Community Edition, which is also a free version of Visual Studio. The application is a quite simple one which simply writes a line of output to the console as below,
 
Running A Visual Studio 2019 Solution In Visual Studio Code
 
Running the application generates the below output,
 
Running A Visual Studio 2019 Solution In Visual Studio Code

Running the solution from Visual Studio Code

To run this application from Visual Studio Code, we need to complete the below steps,
  1. Create a “.vscode” folder at the solution level
  2. Create a “Tasks.json” file
  3. Create a “launch.json” file
The first step is straight-forward. We will look at the second step in which we will create a “Tasks.json” file. This file looks as the below,
  1. {  
  2.     "version""2.0.0",  
  3.     "tasks": [  
  4.         {  
  5.             "label""build",  
  6.             "command""dotnet",  
  7.             "type""process",  
  8.             "args": [ "build" ],  
  9.             "options": {  
  10.                 "cwd""${workspaceFolder}"  
  11.             },  
  12.             "problemMatcher""$tsc"  
  13.         }  
  14.     ]  
  15. }  
In this file we have defined a task to build and run a dotnet application. In the second file named “launch.json” we add the following lines,
  1. {  
  2.     // Use IntelliSense to learn about possible attributes.  
  3.     // Hover to view descriptions of existing attributes.  
  4.     // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387  
  5.     "version""0.2.0",  
  6.     "configurations": [  
  7.         {  
  8.             "name"".NET Launch (console)",  
  9.             "type""clr",  
  10.             "request""launch",  
  11.             "preLaunchTask""build",  
  12.             "program""${workspaceFolder}/cAppVSCode/bin/Debug/cAppVSCode.exe",  
  13.             "args": [],  
  14.             "cwd""${workspaceFolder}",  
  15.             "console""internalConsole",  
  16.             "stopAtEntry"false,  
  17.             "internalConsoleOptions""openOnSessionStart"  
  18.         }  
  19.     ]  
  20. }  
In this file, we define the clr type, and the request to build and launch the application. We also specify the output file (exe in this case).
 
Next, we launch Visual Studio Code and open the folder as below,
 
Running A Visual Studio 2019 Solution In Visual Studio Code

Finally, we click Run and then Run without Debugging. The code will build and run in the debug console as below,
 
Running A Visual Studio 2019 Solution In Visual Studio Code

Please note that I have changed the default theme for Visual Studio Code and installed the Visual Studio solutions extensions.
 

Summary

 
In this article, we looked at a simple example of running a solution created in Visual Studio 2019 community edition in Visual Studio Code. This was a simple console application and there would certainly be more configuration required for more complex applications and for debugging. Please note that the new versions of Visual Studio Code do support building and debugging projects for the .NET framework but this support is very limited.


Similar Articles