I added a new class to my project and got an error saying “Program.Main() has more than one entry”. Why?

后端 未结 9 2305
萌比男神i
萌比男神i 2020-12-06 00:19

The problem is that after I added the new class, the error came up when I did build the solution. What can be wrong?

In Form1, I don’t have any code yet.

I jus

9条回答
  •  感动是毒
    2020-12-06 01:11

    I experienced this issue after adding an xUnit test class to my .NET Core 2.1 project.

    The following article gives a detailed explanation of why, and provided the answer that worked for me - here.

    Basically, the compiler automatically generates a Main for the new class. You can provide a directive in your .csproj file to keep this from happening:

    false

    Add this to your section and recompile.

提交回复
热议问题