0

I have an application to migrate from .net 5 to .net 6, but I don't really get the MS documentation. It says we should transform the two Startup.cs and Program.cs in one Program.cs file but is unclear what kind of content should it have.

say we have

Startup.cs:

using ...

namespace WebAppRPv5
{
    public class Startup {...}

and

Program.cs:

using ...

namespace WebAppRPv5
{
    public class Program {...}

The documentation states (picture bellow):

enter image description here

not clear what is this code, where should it be, in Program.cs? If that, where is the namespace, the usings, the main entry class?

serge
  • 13,940
  • 35
  • 121
  • 205
  • That's the new top level statements. They're "there" you just don't see them or have to explicitly type them. But you can, so if it's tripping you up, add them to make it like you're used to. https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/program-structure/top-level-statements – ChiefTwoPencils Jun 07 '22 at 16:00
  • @ChiefTwoPencils, what do you mean, there is no `Program` class in `Program.cs` file? – serge Jun 07 '22 at 16:01
  • It's there implicitly. Added a link. – ChiefTwoPencils Jun 07 '22 at 16:01
  • @ChiefTwoPencils but the namespace and usings? – serge Jun 07 '22 at 16:02
  • 1
    @serge read up on Top Level Statements from C# 9: https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-9#top-level-statements. All that boiler plate stuff is no longer needed. In the context of the documentation, the "preceding code" line is a reference to the Program.cs file. So if you replace the contents of that file with what they tell you to, you will be ok – maccettura Jun 07 '22 at 16:04
  • it's so radical that Microsoft could better explain for people just migrating that the code bellow does belong to `Program.cs` file (or `Startup.cs`?)... – serge Jun 07 '22 at 16:05
  • also, "global using directives", not really clear, where does it declares shoul it be in Program.cs? – serge Jun 07 '22 at 16:10
  • @serge create an empty .cs file then put all global usings in it, location of the file depends on your desire. – Mustafa Salih ASLIM Jun 21 '22 at 16:21

0 Answers0