Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
NotMyself opened this issue Mar 20, 2017 · 10 comments
Closed

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

NotMyself opened this issue Mar 20, 2017 · 10 comments

Comments

@NotMyself
Copy link

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. I get the following error:

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.

Incase 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

@clairernovotny
Copy link
Member

clairernovotny commented Mar 20, 2017

.NET Core test projects are exe's. They just provide the main method for you... not sure there's a way around that. This would belong in https://github.com/microsoft/vstest/issues as it's an issue with the test platform, not xunit.

@bradwilson
Copy link
Member

That's a mandate right now from VSTest. I don't think it'll be required for dotnet xunit, but I can't make that guarantee yet.

@NotMyself
Copy link
Author

Thanks @bradwilson I'll come up with something until that releases. @onovotny I submitted a bug to vstest. Really weird that they would inject a static void Main into a console application like that and just let it fail to build.

@NotMyself
Copy link
Author

@bradwilson did you see the resolution to this over in microsoft/vstest#636 ? Looks like there is a flag you can set in your csproj to disable this silly behavior.

@bradwilson
Copy link
Member

I honestly have no idea why they did that in the first place. My work showed it to be completely unnecessary now (obviously, since you can provide your own entry point, you don't need theirs).

It used to be that a unit test project in DNX had to be an executable, because of the architecture of that system (the runner was literally an entry point to the program, so that you can write your own Main and accept command line arguments). That hasn't been true since they changed to VSTest. It's possible that they're just doing it out of habit rather than any technical need.

@bradwilson
Copy link
Member

There are some things I'm injecting into the project to get it to generate the artifacts I need (with tons of nods to Nate McMaster who is like my guidebook for .NET Core). Maybe VSTest should take this strategy rather than flipping the project into an executable.

<Project>
  <PropertyGroup>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
    <CopyNuGetImplementations>true</CopyNuGetImplementations>
    <DebugType Condition=""'$(TargetFrameworkIdentifier)' != '.NETCoreApp'"">Full</DebugType>
    <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
    <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
    <GenerateDependencyFile>true</GenerateDependencyFile>
  </PropertyGroup>
</Project>

@bradwilson
Copy link
Member

Closing this as external, because (a) there's a workaround, and (b) it's not our bug.

@Hassan-Ali123
Copy link

I also have this issue in a Window form project. Please help if someone can!

@bradwilson
Copy link
Member

Please don't respond to closed issues. Open a new one, and provide a repro project (otherwise it'll be closed). Thanks!

@danielfedelesumg
Copy link

I also have this issue in a Window form project. Please help if someone can!

https://andrewlock.net/fixing-the-error-program-has-more-than-one-entry-point-defined-for-console-apps-containing-xunit-tests/

kennethmyhra added a commit to kennethmyhra/Helsenorge.Messaging that referenced this issue Feb 7, 2024
To be able to upgrade to MSTest.TestAdapter version 3.2.0, and since we
are using the mocks in some of our example projects I had to move the
mocks into a separate test library to avoid the error: "CS0017 Program
has more than one entry point defined. Compile with /main to specify the
type that contains the entry point."

Not sure why this didn't hit us before, but at least this approach fixes
the problem.

For more information see: xunit/xunit#1172
kennethmyhra added a commit to kennethmyhra/Helsenorge.Messaging that referenced this issue Feb 8, 2024
To be able to upgrade to MSTest.TestAdapter version 3.2.0, and since we
are using the mocks in some of our example projects I had to move the
mocks into a separate test library to avoid the error: "CS0017 Program
has more than one entry point defined. Compile with /main to specify the
type that contains the entry point."

Not sure why this didn't hit us before, but at least this approach fixes
the problem.

For more information see: xunit/xunit#1172
kennethmyhra added a commit to kennethmyhra/Helsenorge.Messaging that referenced this issue Feb 8, 2024
To be able to upgrade to MSTest.TestAdapter version 3.2.0, and since we
are using the mocks in some of our example projects I had to move the
mocks into a separate library to avoid the error: "CS0017 Program has
more than one entry point defined. Compile with /main to specify the
type that contains the entry point."

Not sure why this didn't hit us before, but at least this approach fixes
the problem.

For more information see: xunit/xunit#1172
kennethmyhra added a commit to helsenorge/Helsenorge.Messaging that referenced this issue Feb 8, 2024
To be able to upgrade to MSTest.TestAdapter version 3.2.0, and since we
are using the mocks in some of our example projects I had to move the
mocks into a separate library to avoid the error: "CS0017 Program has
more than one entry point defined. Compile with /main to specify the
type that contains the entry point."

Not sure why this didn't hit us before, but at least this approach fixes
the problem.

For more information see: xunit/xunit#1172
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants