Answers for "setting up C# project with VSCode"

3

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' lists the content of the current directory 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
# (you could use 'cls' to clear the console and make it easier to read)

# 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/suggestions, or contact me (EAJB)
# on the Grepper Discord community.
Posted by: Guest on August-14-2021

Code answers related to "setting up C# project with VSCode"

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language