在标题为 Scaffold Identity in ASP.NET Core projects 的MSDN文章中,有一组专门针对"creating full identity UI source"的说明(而不是使用Razor Class Library for identity)。
本节开头:
要保持对Identity UI的完全控制,请运行Identity scaffolder,然后选择“覆盖所有文件”。
没有给出可以在外壳中运行的命令以对所有这些文件进行脚手架安装,因此我认为“覆盖所有文件”是Visual Studio中的UI控件。
如果我们查看dotnet aspnet-codegenerator identity -h
的输出,我们不会看到任何生成所有文件的选项。
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
鉴于所有这些,dotnet
命令行脚手架工具的用户如何生成身份生成器一部分的文件的 all ?
答案 0 :(得分:5)
如前所述,目前尚无用于生成所有身份文件的命令行选项。
非常感谢--files
和--listFiles
选项可以一起使用以实现该目标。
第1步:列出可以安装的文件
$ 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
我们希望在 之后的所有行“文件列表:”。
第2步:将这些名称组合成以分号分隔的字符串
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
第3步:这次再次运行生成器,为选项--files
提供我们刚刚创建的字符串
我们不能忘记用引号引起来,否则我们的shell可能会尝试将这些文件名作为命令执行(因为;
是命令终止符)。
$ 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"
假设执行成功,我们现在直接在源代码树中拥有所有身份代码(后端代码,UI等)。
参考文献:
答案 1 :(得分:1)
如果省略MYSAFEARRAY
和--files
标志,它将生成所有文件。
--useDefaultUI
根据docs:
如果在未指定
$ dotnet aspnet-codegenerator identity
的情况下运行身份支架 标志或--files
标志,所有可用的Identity UI页面 将在您的项目中创建。
来源: