I have tried running this program a million times. I am in the correct directory, C:\Users\DylanT\Desktop\Project
, and the file is just named Program.cs. When I use the dotnet run
command, I get the error
Couldn't find a project to run. Ensure a project exists in C:\Users\DylanT\Desktop\Project, or pass the path to the project using --project.
I only have one folder named "Project" and the only file inside the folder is the program, so there shouldn't be any reason it shouldn't execute the program. How can I do it?
The .NET Build System does not work with loose .cs files (or F# or VB.NET for that matter); it needs at least a project. You can generate a project file by using dotnet new <template>
as follows:
md MyProject
cd MyProject
dotnet new console
Now you have a folder MyProject
, containing MyProject.csproj
and a default Program.cs
file.
To run it, you can now do
dotnet run
This will open and read the .csproj
file, and it will use the settings and properties that are inside it to build all the source files into an executable, and then it will run that.
As you can read here you have to call the command on a .csproj-file. You simply can not call it on a source code file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With