skip to Main Content

Using Visual Studio for exercises from Code Academy’s virtual console.

I open C# file in Visual Studio (2022 version). When entering ‘dotnet run’ in Powershell, it returns:

‘Couldn’t find a project to run. Ensure a project exists in C/Users/(username)/source/repos, or pass the path using –project.’

What I don’t get is, the .cs file is there, despite terminal saying it isn’t.

Thank you and happy holidays

2

Answers


  1. You can use an existing template that visual studio provides in File -> Add -> New Project. Everything will be set up automatically for you (like .csproj, your main .cs file, etc) so you can just build and run that.

    For something barebones, pick the C# console app and then just do your Code Academy stuff there.

    Login or Signup to reply.
  2. When using dotnet run, you need to pay attention to the following points:

    1. The dotnet run command can only be used to run executable files and cannot be used to run class libraries.
    2. Like general applications, console or form applications must have an entry point Main.
    3. Before using the dotnet run command, make sure that the dotnet build command has been executed so that the executable file can be generated.

    In addition, you can also just use the button to run the program that comes with Visual Studio, and Visual Studio will automatically compile the program for you. Or you can directly press F5 to quickly start

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search