Search code examples
c#.net-corevisual-studio-2017asp.net-core-webapiporting

Porting a solution with multiple startup projects from .NET Framework 4.7.1 to .NET Core 2.1


I'm in the process of migrating my solution from .NET Standard (targeting .NET Framework 4.7.1) to .NET Core (targeting netcoreapp2.1). My solution consists of 12 projects, two of which are web API projects that both need to run simultaneously.

I changed the targets in all my solution's .csproj from "net471" to "netcoreapp2.1". In a few cases I also had to update the APIs in code. There are still several warnings I'm dealing with regarding potential package incompatibility.

However my main problem is the following error:

Error CS0017 Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point. Foo.Api D:\Code\Product\Foo\src\Foo.Api\Program.cs 9 Active

My solution has two startup projects, as it consists of two APIs that are related but separate. I don't want to specify one as the main as I need them both to start up when starting my solution, and under .NET Framework this was no problem.

Is it possible to have these projects start up together?

Note that if I add <StartupObject>Foo.Api.Program</StartupObject> to one of my API projects as described here, I can successfully get that project to start. I think this is equivalent to compiling with /main. I cannot, however, get the other API project to start the same way. Instead, I can dotnet run that project and have them both running. However, the compile time error needs to be resolved for it to get through our release pipeline.

There are definitely only these two Main methods in my solution. Here is the results of a find on void Main:

Enter image description here


Solution

  • My problem is resolved, but I am still not sure what caused it.

    I was referencing a few packages that gave the following warning:

    Warning NU1701 Package 'CacheManager.SystemRuntimeCaching 1.1.2' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.1'. This package may not be fully compatible with your project.

    I upgraded most of them, with the exception above, and I was able to run and debug both startup projects simultaneously without error. My guess is there was some kind of conflict with one of these packages.