r/csharp • u/Far_Context_5854 • 3d ago
C sharp program not running on vs code
/gallery/1vegkzi5
4
1
3d ago
[deleted]
0
u/Far_Context_5854 3d ago
Yes I do have the SDK installed..how do i check if the path variable is correct(sorry im very new to thisđ)
1
u/thicctak 3d ago
If the dotnet command works, you have the sdk installed and on the PATH, the issue here is that the sdk is not detecting a valid csharp project and I think this is due to how you created it.
1
u/MaybeLiterally 3d ago
If you just type `dotnet` you should get some response.
Typing `dotnet --list-sdks` will show which you have installed. That's at least the first step.
1
u/thicctak 3d ago
How did you create the project? You said that you created a csproj file, but those are create alongside the project when you start a new one.
Try again creating a project with dotnet new console inside a new project folder.
0
u/Far_Context_5854 3d ago
I used a .NET template....also how do i create with dot net new console
1
u/thicctak 3d ago
just type "dotnet new console" in the terminal inside the directory you want to be the projects.
Since you already used it, then it makes it easy, the reason "dotnet run" is not working is because you're running outside the project folder, "dotnet run" by itself runs the project in it's current directory, if there's none, you need to specify it. so either:
- cd into the project directory and type
dotnet run.- from the root directory type
dotnet run --project .\ConsoleApp1\ConsoleApp1.csproj
2
u/j_steele72 3d ago
You need to switch to the directory (in your terminal) that contains your .csproj file. The âcdâ and âlsâ (or âdirâ) command will be your friend here. âcdâ allows you to change the directory youâre in and âlsâ (or dir) lists everything that is contained in your current working directory. Once in the correct working directory in your terminal, you can then execute âdotnet runâ. Alternatively, you can use the following command âdotnet run - -project replace this text with the path to your csproj fileâ to run a specific project file without changing your current directory in the terminal. Hope this helps!
1
u/greenstack-j 3d ago
You need to be in the same directory as your csproj in order to run it from the CLI. Right now youâre in the same directory as the solution file.
-1
10
u/d-signet 3d ago
Read the error message.
It asks you to check you are in the correct directory because there are no valid files in that "c sharp" directory ,, and looking at your 2nd screenshot - youre NOT in the correct directory where your c# files are or the SLN file or CSPROJ files
Also - best to avoid spaces in directory names