Search code examples
c#asp.net-core.net-coreasp.net-identityasp.net-mvc-scaffolding

.NET Core Identity - Scaffold pages without overriding existing files


I have a .NET Core 2.2 MVC app using Identity. Since I'm using Visual Studio for Mac I had to use the CLI to scaffold out the identity files. Initially I only needed a few files so I used the following command to generate the files I needed:

dotnet aspnet-codegenerator identity --files="Account.Manage.ChangePassword;Account.Register;Account.ResetPassword;Account.ResetPasswordConfirmation;Account.Manage.SetPassword;Account.Manage.Index"

I'm now trying to generate another file by running:

dotnet aspnet-codegenerator identity --files="Account.Manage.EnableAuthenticator"

but I get the following error: The below files exist. Use '--force' to overwrite: Areas/Identity/Data/SAFDtoolsIdentityDbContext.cs Areas/Identity/Pages/Account/Manage/_ManageNav.cshtml Areas/Identity/Pages/Account/Manage/ManageNavPages.cs

Is it possible to generate additional files without overriding existing files? I don't want to lose any customizations I already made.

Also, if I use --force will only the 3 files in the error get overwritten or will every file I already generated be overwritten??


Solution

  • Each file name(for example Account.Manage.EnableAuthenticator) contains several files which list in identitygeneratorfilesconfig.json templete:

    https://github.com/aspnet/Scaffolding/blob/release/2.2/src/VS.Web.CG.Mvc/Identity/bootstrap4_identitygeneratorfilesconfig.json#L301

    Currently it seems will overwrite the existing files and not find option to disable the behavior , you can use the dotnet aspnet-codegenerator identity --listFiles , it will show the exist files which need to use --force to overwrite .

    Also, if I use --force will only the 3 files in the error get overwritten or will every file I already generated be overwritten??

    It will overwrite the 3 files and you can copy/save the customize part of codes , paste that part of codes to new created files .