Reputation: 2094
I'm creating an application which requires unit tests. I'm using the .NET xUnit-framework.
First, I initialized a new "Hello, World! class" with
dotnet new console
Then I added the unit test
dotnet new xunit
When I run dotnet run
or dotnet test
, I get this error:
error CS0017: Program has more than one entry point defined. Compile with /main to specify the type thatcontains the entry point.
I read about there being a Main defined in the xUnit which interferes with the entry point in Program, but how would I be able to have these separated? That is, how would I be able to run both dotnet run
and dotnet test
?
Upvotes: 0
Views: 490
Reputation: 2094
Found a solution to be able to run both dotnet test
and dotnet run
here.
The problem is that a test project builds its own Program.cs file. You want to add following to your .csproj:
<GenerateProgramFile>false</GenerateProgramFile>
Upvotes: 1
Reputation: 11
You should not run both "dotnet new console" and "dotnet new xunit" in the same directory. They are different projects and they have different entry point.
Upvotes: 1