web-dev-qa-db-ja.com

dotnetを介してすべてのIDファイルをASP.NETCore 2.1 MVCプロジェクトにスキャフォールディングするにはどうすればよいですか?

ASP.NETコアプロジェクトのScaffold IdentityというタイトルのMSDNの記事には、 「完全なIDUIソースの作成」IDにRazorクラスライブラリを使用する代わりに )。

このセクションは次のように始まります。

Identity UIの完全な制御を維持するには、Identity Scaffolderを実行し、[すべてのファイルを上書きする]を選択します。

これらすべてのファイルをスキャフォールディングするためにシェルで実行できるコマンドは指定されていないため、「すべてのファイルをオーバーライドする」はVisualStudioの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コマンドラインスキャフォールディングツールのユーザーは、IDジェネレーターの一部であるファイルのallをどのように生成できますか? ?

7
taryn

--filesフラグと--useDefaultUIフラグを省略すると、すべてのファイルが生成されます。

$ dotnet aspnet-codegenerator identity

docs ごと:

--filesフラグまたは--useDefaultUIフラグを指定せずにIdentityscaffolderを実行すると、使用可能なすべてのIdentityUIページがプロジェクトに作成されます。


出典:

https://github.com/aspnet/Docs/pull/8752

1
Nate Lowry

前述のように、現在、すべてのIDファイルを生成するコマンドラインオプションはありません。

ありがたいことに、--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

すべての行after "File List:"が必要です。

ステップ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に作成した文字列を指定します

引用符で囲むことを忘れないでくださいまたは、シェルがこれらのファイル名をコマンドとして実行しようとする場合があります(;がコマンドターミネーターであるため) )。

$ 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"

これが正常に実行されたとすると、すべてのIDコード(バックエンドコード、UIなど)がソースツリーに直接あります。


参照:

https://github.com/aspnet/Docs/issues/844

https://github.com/aspnet/Scaffolding/issues/872

2
taryn