3

I already have a Program.cs in the folder/directory and no other files.

When I do dotnet new console, it won't let me create it unless I use --force to overwrite the Program.cs. I think I just need to create .csproj project file to build, run and debug it.

Is there a dotnet new console with option to skip Program.cs creation?

Otherwise, I will need to make a new directory and create dotnet new console and then I have to replace the auto-generated Program.cs with my Program.cs.

1 Answer 1

6

Otherwise, I will need to make a new directory and create dotnet new console and then I have to replace the auto-generated Program.cs with my Program.cs.

Well there's a simpler option than that:

  • Rename Program.cs to OldProgram.cs
  • Run dotnet new console
  • Rename OldProgram.cs to Program.cs

Alternatively, just write the csproj file by hand - it's really simple. The default on my machine is:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

</Project>

You could just copy/paste that into the new file...

Sign up to request clarification or add additional context in comments.

1 Comment

Yes. I could do that. What I did was I copy/cut the code in the original Program.cs and then dotnet new console --force. And I just paste the code in the new Program.cs. :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.