Vstest: error CS0017: Program has more than one entry point defined.

Created on 20 Mar 2017  路  5Comments  路  Source: microsoft/vstest

Description

I have a small single project console app called DotNetCoreKoans. It has embedded xunit tests in the project. After running dotnet migrate I can no longer build the project. In case it is not clear what my project looks like here is a screenshot showing the test location and my program.cs where my main method is.

image

This bug is also submitted to xunit/xunit#1172

Steps to reproduce

  1. Clone DotnetCoreKoans
  2. Checkout the vs2017 branch git checkout vs2017
  3. Perform a dotnet restore
  4. Perform a dotnet build

Expected behavior

Console project should successfully build with no errors.

Actual behavior

Engine\Program.cs(8,27,8,31): error CS0017: Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point.

Environment

image

bug ide

Most helpful comment

@NotMyself : You are hitting this issue because vstest is injecting an entry point for all test project. This is done to help users, where test project targets netcoreapp ( we have a tracking bug where entry point is getting added for projects targeting Full .Net here #608 and we plan to fix this in our upcoming releases)

Since your test project is adding entry point itself, you can suppress automatic injection of entry point by adding following line in your csproj

  <PropertyGroup>
    <GenerateProgramFile>false</GenerateProgramFile>
  </PropertyGroup>

All 5 comments

I hit this hard with porting Dapper as well, why is VSTest (if it is), injecting another entry point?

Note: there's another bug here: VS reports the issue is with my net451 build (incorrectly), not the netcoreapp1.0 build that actually has the problem. So there's also an IDE reporting bug around this.

@NickCraver FWIW xUnit looks to be solving this by assuming the responsibility over in xunit/xunit#1172

@NotMyself : You are hitting this issue because vstest is injecting an entry point for all test project. This is done to help users, where test project targets netcoreapp ( we have a tracking bug where entry point is getting added for projects targeting Full .Net here #608 and we plan to fix this in our upcoming releases)

Since your test project is adding entry point itself, you can suppress automatic injection of entry point by adding following line in your csproj

  <PropertyGroup>
    <GenerateProgramFile>false</GenerateProgramFile>
  </PropertyGroup>

@Faizan2304 this seems to resolve my immediate issue. Adding the new property group to my csproj allowed me to successfully run dotnet build, dotnet test and dotnet run. I am resolving this bug in my project.

Was this page helpful?
0 / 5 - 0 ratings