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

Created on 17 Jul 2018  路  17Comments  路  Source: microsoft/vstest

Building a project is blocked for an Empty .NET Core Web Application and after adding the NuGet package Microsoft.NET.Test.Sdk.

The error displayed:

 Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point.

Steps:

  1. Open Visual Studio and create a new Empty .NET Core Web Application.
  2. Add the NuGet package Microsoft.NET.Test.Sdk.
  3. Build the project. Errors out.

Expected:
Builds successfully.

image

question up-for-grabs

Most helpful comment

I tested the GenerateProgramFile property and it does work with the scenario we're implementing. Nonetheless, we feel like this is not the experience we are looking for the user due to the following reasons:

  • Requires for the user to manually add the property. This is not intuitive and the only way for the user to know this is through documentation or figuring out himself by searching for similar issues online.
  • It introduces inconsistency. It is only required for "some" projects as a class library project doesn't requires it. Admittedly, we don't expect a lot of class projects on our scenarios but we still cannot discard that's the case.
  • It's and undocumented property. I didn't found any official documentation of the property but a bunch of posts about similar issues.

Said that, can you reconsider identifying when the project already contains a main method and ignores the setting? Doing this will allow our users to simply add the vstest package plus our test adapter and seamlessly work with JavaScript unit tests.

Looking forward to hearing from you.

All 17 comments

@armanio123 : Why are you trying to consume Microsoft.NET.Test.Sdk package in a Web application project? Would it be possible for you to write your tests in normal net core project?
Can you explain your scenario to us?

This is related to PR: https://github.com/Microsoft/nodejstools/pull/1997, where we're enabling the users to add Javascript unit tests on .net core projects. Most commonly web applications.

To add to @armanio123's comment.

JavaScript unit tests, generally reference the JavaScript in the application. And currently there is no good way to copy these JavaScript files to a separate "Unit test project" (other than perhaps using "linked files", which sounds horrible).

@armanio123 , if you take a look at our SDK's target file we are already adding Main method, which is needed for us to generate appropriate reference for dotnet core UT projects.

I would suggest that rather than adding your logic in Main, can you please move it to some Template TestClass?

@armanio123 , I'm closing this issue, please comment here if it needs to be re-opened

@mayankbansal018 this is not related to any code @armanio123 is adding.. When you add the Microsoft.NET.Test.Sdk to an ASP.NET Core application you'll see this error.

The reason we want to add this package to enable JavaScript unit test scenarios. We're happy to work with you to make this work, but using a class library project won't work (since we wouldn't be able to copy/reference the JavaScript logic in the application).

Hope this clarifies the problem we're seeing

@paulvanbrenk , as per the image attached by armanio earlier, it looks that someone is adding the Main function to an application which takes reference on Microsoft..Net.Test.SDK

As you mentioned you can't use class library, since it doesn't allow javascript reference, so the current option is to create a console asp.net core app, which I suppose would bring in Main method implicitly, & to this asp netcore app you would want to add reference to Test SDK.

Please let me know if I missed anything.

If above is correct, then as I mentioned previously, our test sdk also implicitly tries to add Main method to the unit tests projects(please see reason above), which is causing the build error.

@mayankbansal018 do you still need your generated empty main entry point, when there already is one present?

I can see that would add that conditionally for only classlibrary projects?

@paulvanbrenk , for .netcore UT projects we actually generate an "exe", the reason being, that if create class libraries, we won't get required runtime config that is needed by dotnet.exe to load the dependencies of the test project.

However if we can determine that a main entry point is present, then we might need not generate another.

I'll verify this, & get more details on it tomorrow.

@mayankbansal018 great!

@paulvanbrenk , I verified that we should be okay to not auto generate _main_ program if it is already present.
Can you please raise a PR to determine if the app has _main_ entry point

Bill here, Dev Lead on the Node/TypeScript/JavaScript Tools in VS. Chiming in now that @paulvanbrenk has left the team.

This sounds like entirely a fix needed in the Microsoft.NET.Test.Sdk package right, and not related to any of our components. As such, we have little to zero experience in this codebase, and would be very inefficient in trying to come up with the correct fix. If the team that owns the code could fix the bug, that would be very helpful to us, as it blocks a scenarios we're trying to land currently. (And I assume helpful to anyone else who wishes to use the .NET Test SDK in their ASP.NET Core projects). Thanks.

@billti , @armanio123 A simple option would be set GenerateProgramFile = false in your csrproj. This will tell .net test sdk to not add auto-generated main program. Attached image
disable-auto-generated

@billti @armanio123 any update on this?

Please use GenerateProgramFile property to skip auto generated Main.

I tested the GenerateProgramFile property and it does work with the scenario we're implementing. Nonetheless, we feel like this is not the experience we are looking for the user due to the following reasons:

  • Requires for the user to manually add the property. This is not intuitive and the only way for the user to know this is through documentation or figuring out himself by searching for similar issues online.
  • It introduces inconsistency. It is only required for "some" projects as a class library project doesn't requires it. Admittedly, we don't expect a lot of class projects on our scenarios but we still cannot discard that's the case.
  • It's and undocumented property. I didn't found any official documentation of the property but a bunch of posts about similar issues.

Said that, can you reconsider identifying when the project already contains a main method and ignores the setting? Doing this will allow our users to simply add the vstest package plus our test adapter and seamlessly work with JavaScript unit tests.

Looking forward to hearing from you.

thanks for shareing

Was this page helpful?
0 / 5 - 0 ratings