setting up C# project with VSCode

# Setting up C# project with VSCode:

# 1. Open File Explorer and create a folder on your disk, then select the 
#    file path and to open the Command Prompt at the current path, type: cmd 
#    (For the purpose of this guide, the folder is called 'MyFolder')
#    The Command Prompt should look like this:
Microsoft Windows [Version 10.0.19043.1165]
(c) Microsoft Corporation. All rights reserved.

C:\Users\name\MyFolder>

# 2. Create .sln file and check the directory.
C:\Users\name\MyFolder>dotnet new sln -n "SlnFileName"
C:\Users\name\MyFolder>dir 
# ('dir' shows the directory for current folder so you
#  can check to see any files/folders updates)

# 3. Create new console project folder and check the directory.
C:\Users\name\MyFolder>dotnet new console -n "ProjectName"
C:\Users\name\MyFolder>dir

# 4. Create class library folder and check the directory.
C:\Users\name\MyFolder>dotnet new classlib -n "LibraryName"
C:\Users\name\MyFolder>dir

# 5. Add project to solution.
C:\Users\name\MyFolder>dotnet sln SlnFileName.sln add ./ProjectName/ProjectName.csproj

# 6. Add library to solution.
C:\Users\name\MyFolder>dotnet sln SlnFileName.sln add ./LibraryName/LibraryName.csproj

# 7. Project references the library.
C:\Users\name\MyFolder>dotnet add ProjectName/ProjectName.csproj reference LibraryName/LibraryName.csproj

# 8. Move the command line into a new project folder and check the directory.
C:\Users\name\MyFolder>cd ProjectName
C:\Users\name\MyFolder\ProjectName>dir

# 9. Launch VSCode from cmd. This will open VSCode with the current folder
#    already open. When VSCode has launched, there should be a little pop-up
#    message in the bottom right of the screen saying 'Required assets to
#    build and debug are missing from 'ProjectName'. Add them?'. You want to
#    click 'Yes' to add 'launch.json' and 'tasks.json' files.
C:\Users\name\MyFolder\ProjectName>Code ..

# 10. Now, close VSCode. In cmd, go back one folder, to 'MyFolder'. 
#     Lastly, open VSCode. Your default 'Program.cs' file should be located 
#     in the 'ProjectName' folder.
C:\Users\name\MyFolder\ProjectName>cd ..
C:\Users\name\MyFolder>Code ..

# Please comment if you have any queries, or contact me (EAJB) on the Slack
# community.

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source