C
C#14mo ago
kyky

❔ Visual Studio Code not running C#

I am a beginner coder that is beginning to learn C#. I previously used replit and made the decision today to switch to Visual Studio Code. but when i run a code, nothing shows up in the output. Image:
56 Replies
Thinker
Thinker14mo ago
Firstly, do you have the .NET SDK installed? Secondly, do you have a project or just a single file?
kyky
kyky14mo ago
i believe just a single file, and yes i have the .net 7.0 installed
Thinker
Thinker14mo ago
$vscode
MODiX
MODiX14mo ago
1) Install the C# extension 2) 2.a) DO NOT USE OPEN FILE 2.b) Always use Open Folder (from the File menu), and open the folder containing your .sln file (or the folder containing the .csproj if you have only one .csproj) 3) To make the extension start and detect C#, either: 3.a) wait for the prompt that will appear on the bottom right of your screen that ask you if you want it to create some files, and say Yes 3.b) Command Palette (F1 or Ctrl+Shift+P) and type > .Net : Generate Assets for build and run 4) you should see a flame on the Status bar with the Omnisharp logo (see second attached screenshot) 5) it should load to finally say OmniSharp server is running (if not ask for help) https://media.discordapp.net/attachments/569261465463160900/1006652191689429022/unknown.png https://cdn.discordapp.com/attachments/569261465463160900/951015732769079336/unknown.png
Thinker
Thinker14mo ago
When working with C#, you always have to have a project. You can't run singular files.
kyky
kyky14mo ago
oh i see okay i put the code in a folder and opened it
Thinker
Thinker14mo ago
Do you have a .csproj in that folder?
kyky
kyky14mo ago
yeah oh its a .cs should it be .csproj
Thinker
Thinker14mo ago
no Source code is .cs
kyky
kyky14mo ago
Thinker
Thinker14mo ago
You can run dotnet new console in the folder to create a new console app Then delete the Program.cs file that's generated
kyky
kyky14mo ago
kk
Thinker
Thinker14mo ago
Then run the project using dotnet run
kyky
kyky14mo ago
Thinker
Thinker14mo ago
You're missing a ; after Console.WriteLine("hello world!").
Buddy
Buddy14mo ago
Note that I wouldn't recommend VSCode to a beginner because there's a lot of manual work involved with it, and you need to know dotnet CLI. Prefer Visual Studio, and yes it is different from Visual Studio Code.
kyky
kyky14mo ago
oh oops same error happens
Thinker
Thinker14mo ago
Also if you're going to use VSCode then please install the C# extension for it.
kyky
kyky14mo ago
what should i use then its installed
Thinker
Thinker14mo ago
Visual Studio 2022, if you're on Windows
kyky
kyky14mo ago
its telling me i need like 50 gb 😬
Thinker
Thinker14mo ago
yeah that's the downside
kyky
kyky14mo ago
i dont have enough room for it and i heard VS code is more lightweight
Thinker
Thinker14mo ago
yikes well VSCode is more lightweight, but it's also a lot more manual than VS
kyky
kyky14mo ago
i see anything else you would suggest?
Thinker
Thinker14mo ago
Rider but that's not free and also pretty hefty in terms of size Anyway, VSCode Did you add a semicolon on line 5 and save the file?
kyky
kyky14mo ago
yes
Thinker
Thinker14mo ago
then it should work
kyky
kyky14mo ago
😭 oh this popped up
kyky
kyky14mo ago
Thinker
Thinker14mo ago
looks fine
kyky
kyky14mo ago
oh it works but only if i do dotnet run the run button doesn't work?
Thinker
Thinker14mo ago
do you have a .vscode folder with launch.json and tasks.json?
kyky
kyky14mo ago
no
kyky
kyky14mo ago
Thinker
Thinker14mo ago
open the command palette and type generate assets for build and run and run the action that pop up
kyky
kyky14mo ago
kyky
kyky14mo ago
what should i do @🌈 Thinker 🌈
Thinker
Thinker14mo ago
I don't know, sorry
circles.png
circles.png14mo ago
switch the useModernNet setting on
kyky
kyky14mo ago
the what how do i do that
circles.png
circles.png14mo ago
control shift p > open user settings ui
kyky
kyky14mo ago
it was already on when i click run it shows this
kyky
kyky14mo ago
kyky
kyky14mo ago
is that normal?
circles.png
circles.png14mo ago
yes but this is attach mode you can probably switch it to launch mode
kyky
kyky14mo ago
wdym i've never used vs code before 😭
circles.png
circles.png14mo ago
circles.png
circles.png14mo ago
dropdown done?
circles.png
circles.png14mo ago
now restart vscode just in case
circles.png
circles.png14mo ago
control shift p
kyky
kyky14mo ago
okay wait thats not there
circles.png
circles.png14mo ago
just restart vscode
kyky
kyky14mo ago
okay now what
circles.png
circles.png14mo ago
should work
Accord
Accord14mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.