❔ 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
Firstly, do you have the .NET SDK installed?
Secondly, do you have a project or just a single file?
i believe just a single file, and yes i have the .net 7.0 installed
$vscode
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.pngWhen working with C#, you always have to have a project. You can't run singular files.
oh i see
okay i put the code in a folder and opened it
Do you have a .csproj in that folder?
yeah
oh its a .cs
should it be .csproj
no
Source code is .cs
You can run
dotnet new console
in the folder to create a new console app
Then delete the Program.cs
file that's generatedkk
Then run the project using
dotnet run
You're missing a
;
after Console.WriteLine("hello world!")
.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.
oh oops
same error happens
Also if you're going to use VSCode then please install the C# extension for it.
what should i use then
its installed
Visual Studio 2022, if you're on Windows
its telling me i need like 50 gb 😬
yeah that's the downside
i dont have enough room for it
and i heard VS code is more lightweight
yikes
well VSCode is more lightweight, but it's also a lot more manual than VS
i see
anything else you would suggest?
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?
yes
then it should work
😭
oh this popped up
looks fine
oh it works
but only if i do dotnet run
the run button doesn't work?
do you have a
.vscode
folder with launch.json
and tasks.json
?no
open the command palette and type
generate assets for build and run
and run the action that pop upwhat should i do
@🌈 Thinker 🌈
I don't know, sorry
switch the
useModernNet
setting onthe what
how do i do that
control shift p > open user settings ui
it was already on
when i click run it shows this
is that normal?
yes
but this is attach mode
you can probably switch it to launch mode
wdym
i've never used vs code before 😭
dropdown
done?
now restart vscode just in case
control shift p
okay
wait
thats not there
just restart vscode
okay now what
should work
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.