Reputation: 671
In the MSDN article titled Scaffold Identity in ASP.NET Core projects there is a set of instructions specifically for "creating full identity UI source" (instead of using the Razor Class Library for identity).
This section starts with:
To maintain full control of the Identity UI, run the Identity scaffolder and select Override all files.
There is no command given that can be ran in a shell to scaffold all of these files so I assume "override all files" is a UI control in Visual Studio.
If we look at the output of dotnet aspnet-codegenerator identity -h
we will not see any option to generate all files.
Usage: aspnet-codegenerator [arguments] [options]
Arguments:
generator Name of the generator. Check available generators below.
Options:
-p|--project Path to .csproj file in the project.
-n|--nuget-package-dir
-c|--configuration Configuration for the project (Possible values: Debug/ Release)
-tfm|--target-framework Target Framework to use. (Short folder name of the tfm. eg. net46)
-b|--build-base-path
--no-build
Selected Code Generator: identity
Generator Options:
--dbContext|-dc : Name of the DbContext to use, or generate (if it does not exist).
--files|-fi : List of semicolon separated files to scaffold. Use the --list-files option to see the available options.
--listFiles|-lf : Lists the files that can be scaffolded by using the '--files' option.
--userClass|-u : Name of the User class to generate.
--useSqLite|-sqlite : Flag to specify if DbContext should use SQLite instead of SQL Server.
--force|-f : Use this option to overwrite existing files.
--useDefaultUI|-udui : Use this option to setup identity and to use Default UI.
--layout|-l : Specify a custom layout file to use.
--generateLayout|-gl : Use this option to generate a new _Layout.cshtml
Given all of this how can users of the dotnet
command-line scaffolding tool generate all of the files that are part of the Identity generator?
Upvotes: 22
Views: 9951
Reputation: 1
I tried this and it worked (on asp.net core 6.0), but it turned out to not really different than not having a --file value at all. Regardless I thought someone might find it useful
dotnet aspnet-codegenerator identity -dc MyApp.Data.ApplicationDbContext --files "$(dotnet aspnet-codegenerator identity -dc MyApp.Data.ApplicationDbContext --listFiles | grep "Account.*" | tr '\n' ';')"
basically you're taking the command that generates the files, then feeding to it the list of possible files (they all start with 'Account.', thus the grep), with all the new lines from that output translated into semi-colons.
For some reason I thought listFiles would a slightly more specific-to-my-application list but it's not.
Upvotes: 0
Reputation: 501
If you omit the --files
and --useDefaultUI
flags it will generate all the files.
$ dotnet aspnet-codegenerator identity
Per the docs:
If you run the Identity scaffolder without specifying the
--files
flag or the--useDefaultUI
flag, all the available Identity UI pages will be created in your project.
Sources:
https://github.com/aspnet/Docs/pull/8752
Upvotes: 21
Reputation: 671
As noted there is currently no command-line option to generate all of the identity files.
Thankfully the --files
and --listFiles
options can be used together to achieve this goal.
Step 1: List the files that can be scaffolded
$ dotnet aspnet-codegenerator identity --listFiles
Building project ...
Finding the generator 'identity'...
Running the generator 'identity'...
File List:
Account.AccessDenied
Account.ConfirmEmail
Account.ExternalLogin
Account.ForgotPassword
Account.ForgotPasswordConfirmation
Account.Lockout
Account.Login
Account.LoginWith2fa
Account.LoginWithRecoveryCode
Account.Logout
Account.Manage._Layout
Account.Manage._ManageNav
Account.Manage._StatusMessage
Account.Manage.ChangePassword
Account.Manage.DeletePersonalData
Account.Manage.Disable2fa
Account.Manage.DownloadPersonalData
Account.Manage.EnableAuthenticator
Account.Manage.ExternalLogins
Account.Manage.GenerateRecoveryCodes
Account.Manage.Index
Account.Manage.PersonalData
Account.Manage.ResetAuthenticator
Account.Manage.SetPassword
Account.Manage.TwoFactorAuthentication
Account.Register
Account.ResetPassword
Account.ResetPasswordConfirmation
We want all of the lines after "File List:".
Step 2: Combine these names into a semi-colon-delimited string
Account.AccessDenied;Account.ConfirmEmail;Account.ExternalLogin;Account.ForgotPassword;Account.ForgotPasswordConfirmation;Account.Lockout;Account.Login;Account.LoginWith2fa;Account.LoginWithRecoveryCode;Account.Logout;Account.Manage._Layout;Account.Manage._ManageNav;Account.Manage._StatusMessage;Account.Manage.ChangePassword;Account.Manage.DeletePersonalData;Account.Manage.Disable2fa;Account.Manage.DownloadPersonalData;Account.Manage.EnableAuthenticator;Account.Manage.ExternalLogins;Account.Manage.GenerateRecoveryCodes;Account.Manage.Index;Account.Manage.PersonalData;Account.Manage.ResetAuthenticator;Account.Manage.SetPassword;Account.Manage.TwoFactorAuthentication;Account.Register;Account.ResetPassword;Account.ResetPasswordConfirmation
Step 3: Run the generator again this time giving the option --files
the string we just created
We can't forget to surround with quotes or our shell may attempt to execute these file names as commands (because ;
is the command terminator).
$ dotnet aspnet-codegenerator identity --files="Account.AccessDenied;Account.ConfirmEmail;Account.ExternalLogin;Account.ForgotPassword;Account.ForgotPasswordConfirmation;Account.Lockout;Account.Login;Account.LoginWith2fa;Account.LoginWithRecoveryCode;Account.Logout;Account.Manage._Layout;Account.Manage._ManageNav;Account.Manage._StatusMessage;Account.Manage.ChangePassword;Account.Manage.DeletePersonalData;Account.Manage.Disable2fa;Account.Manage.DownloadPersonalData;Account.Manage.EnableAuthenticator;Account.Manage.ExternalLogins;Account.Manage.GenerateRecoveryCodes;Account.Manage.Index;Account.Manage.PersonalData;Account.Manage.ResetAuthenticator;Account.Manage.SetPassword;Account.Manage.TwoFactorAuthentication;Account.Register;Account.ResetPassword;Account.ResetPasswordConfirmation"
Assuming that executed successfully we now have all of the identity code (backend code, UI, etc) directly in our source tree.
References:
https://github.com/aspnet/Docs/issues/8443
https://github.com/aspnet/Scaffolding/issues/872
Upvotes: 15