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