Can't run any C# codes in Visual Studio Code

EMANUEL SANDOVAL ZEDAN VIEIRA 0 Reputation points
2024-08-28T00:35:06.92+00:00

Hello,

I'm studying Computer Science and I need to use Visual Studio Code to program in C#, but when I press the run button, nothing happens. I asked my teacher, Copilot and researched on the internet, but I didn't find anything about it. When I press run via the "Run" button in the top bar of the window, the application says that there is no project loaded. I executed some commands that Copilot gave me in the terminal, but it says that there is no project and when I try to open it directly, it says that there is no file in the specified path. I have already created several new projects and new files, but nothing happens, the same message appears. Everything is properly installed. Please help me solve this and explain it to me in more detail because I don't know Visual Studio Code in depth.

Note: the dotnet build command returns an error (copilot says something is corrupt).

Imagem

I know the image is bad, I'll take another print if I need to. This is another problem I need to solve, but it's beside the point.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,857 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 64,566 Reputation points
    2024-08-28T16:22:51.4366667+00:00

    in vs code you need to open the folder that contains the project. you also need to install c# dev kit extension. before selecting the debug pane, you select the program.cs file, so the debugger knows what to debug.

    a compile happens before debug. if the compile fails, you must fix the compile. you can open terminal, check that your in project folder. then type

    % dotnet build

    to get build errors.

    to check you installed dotnet correctly try:

    % ## check dotnet sdks installed
    % dotnet --list-sdks 
    % ## create a folder and switch to it
    % mkdir testapp
    % cd testapp
    % ## create test app, build and run
    % dotnet new console
    % dotnet build
    % dotnet run 
    % ## open in vs code
    % code .
    

    if this also works, try with visual studio code.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.