How to Fix the Multiple Entry Points Error in .Net Applications

Before I start making changes, I usually run the template code to see if everything works so far. Even when it only has the template code, problems could happen. A few weeks ago, I skipped this step and after I made my changes, I got this error:

Error (active) CS0017 Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point.

That specific error was new to me. I have no idea if the problem was based on the template, version 17.14.0 of Visual Studio or had anything to do with any other extension.

I checked all the code, but there was no other main method. With a bit of digging, I found a solution that fixed the problem. Add this line to the *.csproj file:

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <GenerateProgramFile>false</GenerateProgramFile>
  </PropertyGroup>

  ...

Save the project, rebuild the solution and now everything should be back in a working state.