首页 > 解决方案 > 无法将自定义用户数据添加到脚手架 ASP.NET Core 项目

问题描述

我试图弄清楚如何使用 dotnet cli 工具将自定义配置文件数据添加到剃须刀网络应用程序中。此 Web 应用程序针对 dotnet core 3.0 sdk。但是,当我尝试运行代码生成器工具时,我一直遇到错误。

我已经恢复了我在错误消息中看到的所有包,但这还不够。

这些是我添加到项目中的包。

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.0.0">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0" />
  </ItemGroup>

预期的结果是让应用程序告诉我它工作正常并创建文件。相反,我在控制台中不断收到此错误。

Account.Manage.Index : The term 'Account.Manage.Index' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:74
+ ... tor identity -u WebApp1User -fi Account.Register;Account.Manage.Index
+                                                      ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Account.Manage.Index:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

除了注册之外,我没有索引页面或任何其他主要页面。奇怪的是,我的用户和数据库上下文确实生成了。我很困惑为什么会这样。该网站上的说明没有提及它。https://docs.microsoft.com/en-us/aspnet/core/security/authentication/add-user-data?view=aspnetcore-3.0&tabs=netcore-cli

标签: c#asp.net-core

解决方案


试试这个:

dotnet aspnet-codegenerator identity -u WebApp1User --files "Account.Register;Account.Manage.Index"

看起来这些文档中可能有错字。您可以在此处查看更完整的说明:ASP.NET Core 项目中的脚手架标识

更新:

文档中没有错字。请参阅下面Chris Pratt的评论,了解您在 PowerShell 中遇到该错误的原因。


推荐阅读