dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 3.0.100
Commit: 04339c3a26
Runtime Environment:
OS Name: Mac OS X
OS Version: 10.15
OS Platform: Darwin
RID: osx.10.15-x64
Base Path: /usr/local/share/dotnet/sdk/3.0.100/
Host (useful for support):
Version: 3.0.0
Commit: 7d57652f33
.NET Core SDKs installed:
3.0.100 [/usr/local/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.App 3.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
我创建了一个新的 ASP.Net 核心 MVC Web 应用程序并添加了包:
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
dotnet add package Microsoft.EntityFrameworkCore
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
dotnet add package Microsoft.EntityFrameworkCore.Design
dotnet add package Microsoft.AspNetCore.Identity
我尝试运行命令:
dotnet aspnet-codegenerator identity -h
我得到:
Selected Code Generator: identity
No code generator found with the name 'identity'.
为什么"标识"在更新 SDK 和运行时后不是有效的代码生成器?
通过使用dotnet add package
命令行,它将在.csproj文件中生成以下引用:
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.0" />
</ItemGroup>
将版本更改为 3.0.0,如下所示:
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0" />
我在 .Net 6 中的脚手架标识页面中遇到了相同的错误消息。
找不到名称为"身份"的代码生成器。
重新安装软件包没有帮助。
dotnet aspnet-codegenerator identity
导致错误
无法执行,因为找不到指定的命令或文件。
所以手动安装了代码生成器(提升!
dotnet tool install -g dotnet-aspnet-codegenerator
之后,我再次尝试在Visual Studio中使用脚手架。同样的错误。然后我尝试使用dotnet:
dotnet aspnet-codegenerator identity
现在奏效了。
哦,我配置了一个预构建事件,这在基架期间引起了问题。删除基架的预生成事件,并在工作后重新添加它。