C
C#2y ago
qki

❔ Setting up C# in VSCode

So I'm trying to learn c# right now, but when I try to run a test program, it just throws an error: I have no idea where this "scriptcs" comes from. I ran a search but couldn't find it. What am I doing wrong?
27 Replies
anita
anita2y ago
You cant just run a cs file You need as .csproj
qki
qkiOP2y ago
so rename the file?
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
anita
anita2y ago
No. Create a new project with „dotnet new console“
qki
qkiOP2y ago
aight, one sec
anita
anita2y ago
You need the .net sdk installed And then run it with „dotnet run“
Thinker
Thinker2y ago
dotnet new console -n MyApp
cd MyApp
dotnet run
dotnet new console -n MyApp
cd MyApp
dotnet run
This is the minimum for a regular app
qki
qkiOP2y ago
Not sure if I did it right. Is this what it's supposed to look like?
anita
anita2y ago
Delete the start.csproj But other than that, yes, looks good
qki
qkiOP2y ago
still throws that not recognized error:
Angius
Angius2y ago
Don't use scriptcs Use dotnet run Just dotnet run As long as you're in the directory the .csproj is in
anita
anita2y ago
.
qki
qkiOP2y ago
I see it works with dotnet run in terminal... is there a way i can make it work with coderunner?
Thinker
Thinker2y ago
coderunner?
qki
qkiOP2y ago
isnt that what that extension is called? where you get the run button top right?
anita
anita2y ago
This is also valid c#, you dont need a main method, class, namespace etc
Pobiega
Pobiega2y ago
read the instructions from Modix again: $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
Pobiega
Pobiega2y ago
especially step 3 to 5
qki
qkiOP2y ago
Gotcha, ill try that when i get home
Mayor McCheese
There is a dotnet tool to run scripts actually
anita
anita2y ago
GitHub
GitHub - dotnet-script/dotnet-script: Run C# scripts from the .NET ...
Run C# scripts from the .NET CLI. Contribute to dotnet-script/dotnet-script development by creating an account on GitHub.
Mayor McCheese
csx is just a c# file with an x, by convention
anita
anita2y ago
ahh, ok, i actually have never used, just heard of it before
Mayor McCheese
it's a weird animal, by the time you're done writing the script you could have just used powershell/python
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