30 May 2022

From VS to VS Code with .NET Core

Converting From Visual Studio to Visual Studio Code with ASP .NET Core

There are many blog posts on comparing Visual Studio and Visual Studio Code (e.g. https://www.codeguru.com/visual-studio/visual-studio-vs-visual-studio-code/ ). The main difference I see is that Visual Studio started off as the standard IDE for Windows desktop development only running on Windows, whereas Visual Studio Code, a much more light weight and multi-platform product, focused on web development and quickly became very popular among web developers on all operating systems.

 

On the https://learnforge.autodesk.io/#/ website we have tutorials for multiple frameworks, including ASP.NET Core.
One great thing about this technology, compared to .NET Framework, is that it can be run on multiple operating systems and debugged in Visual Studio Code as well ? 

 

How to Choose Visual Studio or Visual Studio Code

The steps in our tutorials cover how you can create such projects in Visual Studio 2019 Community. I'm running Windows in a Virtual Machine (VM) however, and would prefer to run them on my main OS instead, which is macOS 
(note: you can find the source code of the tutorials on github in projects with the word "learn" in their name: https://github.com/Autodesk-Forge?q=learn). Visual Studio 2019 is available on Mac as well, but supposedly, it's quite different from its Windows version, so I thought running it using Visual Studio Code would be better.

Steps for Converting Visual Studio Code

There were a few things to do to achieve that: 

1) Make sure you have .NET Core 3 SDK installed 
https://dotnet.microsoft.com/download/dotnet-core/3.1

2) Make sure you have the C# Visual Studio Code extension installed
https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp

3) Open the folder containing the *.csproj file of the ASP.NET Core project in Visual Studio Code

4) Open debug tab to create a launch.json file

Create launch.json

This will create both launch.json for running/debugging the app and tasks.json for building it

Now when I tried to debug it, I ran into this problem saying 

> Executing task: dotnet build /Users/nagyad/Documents/GitHub/adamenagy/QuickerAssemblerDA/forgesample/forgesample.csproj /property:GenerateFullPaths=true /consoleloggerparameters:NoSummary <

execvp(3) failed.: No such file or directory
The terminal process terminated with exit code: 1

Debug issue

5) Copy the environment variables from launchSettings.json to launch.json

Copy environment variables

6) Make sure "terminal.integrated.inheritEnv" is true
For some reason in my VS Code this option was set to false so it could not find dotnet, but it should be true 
Someone else ran into this issue as well: https://github.com/OmniSharp/omnisharp-vscode/issues/3447

"terminal.integrated.inheritEnv": true,

Change settings

7) On Mac you might have to create a symbolic link so that VS Code can find dotnet
Mentioned here: https://github.com/dotnet/core/issues/2751#issuecomment-493720465

sudo ln -s /usr/local/share/dotnet/dotnet /usr/local/bin/

That was it! Now I can run my ASP.NET Core app on my Mac inside Visual Studio Code.

Debugging in Visual Studio Code

Tags:

Related Article