Creating a .NET 6 projects based on a .NET 5

JORGE MALDONADO BARRERA 211 Reputation points
2021-12-14T18:07:20.287+00:00

Hello,

I am developing an ASP.NET Core web application and currently I am using .NET Core 5. I am planning to start working with .NET 6 but I do not want to perform an upgrade of the existing .NET 5 but I want to keep it. So, I will be creating a new .NET 6 project and include the .NET 5 files to it and also make the necessary changes like unifying Startup.cs and Program.cs content. Everything seems more or less straightforward. However, my application uses Individual Accounts Authentication so there is a Data / Migrations folder structure which contains Migrations and Application DB Context information. I already have a database that contains a few users for testing purposes.

Should I just copy this Data / Migrations folder structure in my new .NET 6 Project just like that?
What is the correct process to include an existing Individual Accounts Authentication in the new .NET 6 project?

My goal is to use the exact same Individual Accounts Authentication I already have implemented in my .NET 5 project.

Best regards,
Jorge Maldonado

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,162 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. AgaveJoe 26,201 Reputation points
    2021-12-14T18:21:58.66+00:00

    Simply copy the project then migrate the copy using the migration guide(s).

    Migrate from ASP.NET Core 5.0 to 6.0

    0 comments No comments

  2. Michael Taylor 48,046 Reputation points
    2021-12-14T19:27:23.753+00:00

    Are you already using Git to manage your source code? If so then create a new branch from your master. Then make all your changes on your existing solution/project in the branch. Commit changes to that branch as you go along following the instructions for migrating from .NET 5 to .NET 6. There is no real benefit in creating a separate folder structure provided you're using source control. When you are ready to eventually switch to .NET 6 then you can merge your branch into master just like you would any other change.

    0 comments No comments

  3. Zhi Lv - MSFT 32,011 Reputation points Microsoft Vendor
    2021-12-15T06:24:45.21+00:00

    Hi @JORGE MALDONADO BARRERA ,

    First, when you create the new Asp.net 6 application, you could also select the "Individual Accounts" Authentication, then the application will also have the Data / Migrations folder

    157658-image.png

    Second, you can refer the following screenshot to know the difference between select or not select the "Individual Accounts" Authentication

    157717-capture.png

    From the following screenshot, you can see that for the Individual Accounts application (select the "Individual Accounts" Authentication when create new application), since the the "Individual Accounts" Authentication will using Asp.net core Identity and Entity Framework Core to map the SQL Server database and manage users or roles, it has already installed the Asp.net core Identity related packages and the Entity Framework Core related package. And it has add the Identity Area and the Data folder (it contains the EF core dbcontext and the migration files) and the login partial.

    If you compare the program.s file, you can find that the Individual Accounts application already configured the EF core DBContext and the Asp.net core Identity services.

    157771-capture1.png

    So, in the Individual Accounts application, we could directly use the Asp.net core Identity.

    Should I just copy this Data / Migrations folder structure in my new .NET 6 Project just like that?
    What is the correct process to include an existing Individual Accounts Authentication in the new .NET 6 project?

    In your scenario, the easiest way was to create a new .Net 6 Application with select the "Individual Accounts" Authentication.

    For the Application without selecting the "Individual Accounts" Authentication, you have to install the Identity and EF core related package manually (you can install them via Nuget). Then, there is no need to copy the full Data/Migration folder, just create a Data folder and add a new ApplicationDbContext and copy the class content. Then, configure the ApplicationDbContext and the Identity Service in the Program.cs file, after that enable migration it will auto generate the migration file in the Data/Migration folder.

    [Note] when you copy file from .Net 5 application to the .Net 6 Application, please note the namespace.

    After that you can refer to the Scaffold Identity to use Identity.

    Besides, there have another choice, you can make a copy of the .Net 5 project, then refer to this article to update it from .Net 5 to .Net 6, after migration success, you will have two version applications.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Dillion

    0 comments No comments