loading...
Cover image for Launch .Net Core with VSCode for starters

Launch .Net Core with VSCode for starters

bitsmonkey profile image bitsmonkey ・2 min read

To use VSCode for .net core you would need Omnisharp extension so that we can debug our application just like as in Visual Studio.
Using the dotnet new command we create a web and an API project

dotnet new webapp appname.web
dotnet new webapi appname.api

Create a solution so that it wraps all the projects in one place

dotnet new sln appname
dotnet sln add appname.web appname.api

After building the Web and the API projects we need to create the launch.json which VScode refers to build and debug the application. For a complete reference on doing these projects consider this great resource.

You can always use VSCode terminal to run these above commands as well, also note you can open multiple terminals the same VSCode instance like this.

Setup the launch.json by clicking on add configuration and select .Net core web app. we will need to add two such configurations one for web and another for web api. 
For web api you need to launch the browser on running the app, disable 

launchBrowser.enabled: false

we need to update the Url's for both our applications with different ports

env.ASPNETCORE_URLS: "https://localhost:5001"

The build task for the project is defined in tasks.json to which the preLaunchTask references. In below example launch.json I have created two tasks to be executed before running the application. This is how we execute multiple tasks we need to chain each task with the first task name mentioned in preLaunchTask and the rest in tasks.json dependsOn property.

F5 and launch with debug mode on!

Below are the complete launch.json and tasks.json

-originally posted on Bitsmonkey

Discussion

pic
Editor guide
 

I'll try it. I'm in a new job with lots of .net MVC stuff

 

Good Luck to you (y). This is probably the best time to be working on MS tech stack.