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

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

Closed
tonysneed opened this issue Feb 12, 2022 · 4 comments

Comments

@tonysneed
Copy link

tonysneed commented Feb 12, 2022

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.

@tdykstra
Copy link
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.

@tonysneed
Copy link
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.

@adegeo
Copy link
Contributor

adegeo commented Feb 23, 2022

@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

@tdykstra
Copy link
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
Projects
None yet
Development

No branches or pull requests

5 participants