the namespaces are not the issue. when an exe is built, there can only be one declared entry point. one of the projects should be a library, or they should not reference each other.
Referencing multiple projects with top-level statements
I have two projects A and B. Each project has a single top-level statement Program.cs file. I made the Program
class visible from each project by enabling internals:
<InternalsVisibleTo Include="MyTargetProject" />
The problem is that trying to reference Program
class in the target project that has references to both A and B results in a compiler error:
The type 'Program' exists in both 'A, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' and 'B, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
Trying to define Program
class by the namespace (project name) doesn't work. As far as I understand, by default, the compiler doesn't generate a namespace for a top-level class. Is there a way to specify a namespace for a top-level statement file?
I'm aware that a workaround would be to convert at least one Program.cs to a "classic" class with a namespace declaration and the Main
method as its entry point. However, I would like to avoid doing it and continue using top-level statements if it's possible. Is there any way to achieve this?