I have an ASP.NET Core 6 MVC web app, and using VS 2022.
我有一个ASP.NET Core 6 MVC Web应用程序,使用的是VS 2022。
It's a simple web store project with a few products listed and shopping cart added. The web site works, I can see products, details, pictures and add to shopping cart.
这是一个简单的网上商店项目,列出了一些产品和购物车添加。网站工作,我可以看到产品,细节,图片和添加到购物车。
But when I try to add a Razor view of any object of any type (create, edit, list), I get this error:
但是,当我尝试添加任何类型(创建、编辑、列表)的任何对象的Razor视图时,我收到以下错误:
No code generators found with the name 'view'
at Microsoft.VisualStudio.Web.CodeGeneration.CodeGeneratorsLocator.GetCodeGenerator(String codeGeneratorName)
at Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(String[] args)
Project file has all references correct with correct versions:
项目文件的所有引用都是正确的,版本正确:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>bbd1355e-1244-42ae-9d11-e1c7a7bd0a2b</UserSecretsId>
<StartupObject></StartupObject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.16" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.16" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.16">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.16" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.16">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NETCore.App" Version="2.1.30" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.16" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
I have latest packages installed, uninstalled and reinstalled and still get same error.
我安装、卸载并重新安装了最新的程序包,但仍然出现相同的错误。
Checking available code generators shows that they are all installed:
检查可用的代码生成器显示它们都已安装:
I suspect it could be related to the Microsoft.AspNetCore.Identity.EntityFrameworkCore
package, but I'm not sure how to get around it without it, since it's needed for the project.
我怀疑它可能与Microsoft.AspNetCore.Identity.EntityFrameworkCore包有关,但我不确定如何在没有它的情况下绕过它,因为它是项目所需的。
I spent the last 2 days googling, but could not find a solution.
我花了两天时间在谷歌上搜索,但找不到解决方案。
Can someone help?
有人能帮帮忙吗?
Thank you.
谢谢。
更多回答
Elaborate on "add a razor view of any object of any type", what steps are taking?
详细说明“添加任何类型的任何对象的剃须刀视图”,正在采取哪些步骤?
For example right click on the object folder in "view" folder, --> add view --> razor view --> choose view name, template (edit, create, list), model class and context class --> add. visual studio tries to do scaffolding, generatig code but then throws this error..
例如,右击“view”文件夹中的对象文件夹,-->Add view-->razor view-->选择view name、模板(EDIT、CREATE、LIST)、模型类和上下文类-->Add。Visual Studio尝试进行脚手架、生成代码,但随后引发了此错误。
what does dotnet tool list -g
show?
DotNet工具列表-g显示什么?
It shows: dotnet-aspnet-codegenerator 7.0.9 and dotnet-ef 7.0.10
显示:DotNet-Aspnet-CodeGenerator 7.0.9和DotNet-ef 7.0.10
trying to create view from terminal i get this error ''' " Could not
load file or assembly 'Microsoft.EntityFrameworkCore,
Version=6.0.21.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
Try to add package Microsoft.EntityFrameworkCore.Design 6.0.21
尝试添加包Microsoft.EntityFrameworkCore.Design 6.0.21
Change the Version to 6.0.21 like below:
将版本更改为6.0.21,如下所示:
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.21">
I ended up creating new project, and building everything from 0.
Installed all latest packages. I think the problem was related to DBcontext declaration, its declaration in program.cs, and connection string in appsettings.json. But still not sure why, because when i tried to fix everything in existing project to match new project - it did not work.. maybe some internal bug.
我最终创建了新项目,并从0开始构建所有内容。已安装所有最新程序包。我认为这个问题与DBContext声明、它在Program.cs中的声明以及appsettings.json中的连接字符串有关。但仍然不确定为什么,因为当我试图修复现有项目中的所有内容以匹配新项目时-它不起作用。可能是内部的缺陷。
更多回答
Yes, I tried that. Did not work.
是的,我试过了。但没有奏效。
Hi@mer063 , I think it was related to the packages version, not related to DBcontext declaration, because I add declaration in program.cs, and connection string in appsettings.json too. I add the package 6.0.16 and reproduce the error, then I replace the latest packages, and it works. Maybe about reinstall problem, we need make sure we install the package Microsoft.EntityFrameworkCore.Design 6.0.21
.
Hi@mer063,我认为它与包版本有关,与DBContext声明无关,因为我在Program.cs中添加了声明,在appsettings.json中也添加了连接字符串。也许关于重新安装的问题,我们需要确保我们安装了包Microsoft.EntityFrameworkCore.Design 6.0.21。
This is possible. Good to know. Thank you.
这是可能的。很高兴知道。谢谢。
我是一名优秀的程序员,十分优秀!