Skip to content

Use the old program style: Add info on converting top-level statements to explicit entry point #28223

Closed

Description

@tonysneed

In the section, Use the old program style, add information on how to convert an existing .NET 6 console or web app to use an explicit entry point instead of top-level statements. For example, in a .NET 6 console app you can simply replace the code in Program.cs with the following:

namespace MyConsoleApp;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello World!");
    }
}

An example should also be included for adding an explicit entry point to a web app.


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Activity

  1. self-assigned this
    on Feb 14, 2022
  2. tdykstra commented on Feb 14, 2022

    @tdykstra
    Contributor

    Thanks for the suggestion, but this article is about creating new projects, and it already shows the old template code near the top of the article. Web app templates are covered in the ASP.NET Core documentation.

  3. tonysneed commented on Feb 14, 2022

    @tonysneed
    Author

    @tdykstra Is there another place in the docs which covers converting an existing .NET 6 console or web app to use an explicit entry point?

    By way of background, the question came up for me with an integration tests that needed to reference more than one web project. Because Program now exists in the global namespace, it caused an ambiguous reference in the test project.

  4. adegeo commented on Feb 23, 2022

    @adegeo
    Contributor

    @tdykstra this may be a missing scenario, approaching it from the point of view that @tonysneed is indicating. In general the requests have been from the context of "restore the old template" which the article covers. But the context here, I believe, is a missing scenario: "How do I specify an entry point for an app"

    This would include:

    • Remove the top-level statements from the code
    • Create a namespace + class
    • Add a static method named Main
  5. tdykstra commented on Feb 23, 2022

    @tdykstra
    Contributor

    That doesn't seem to fit the context of an article that is specifically about project creation using the template. Maybe it would fit in https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/program-structure/top-level-statements#implicit-entry-point-method -- we could add "if you need an explicit entry point" text. @BillWagner what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions