You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

学习Contoso University教程时运行aspnet-codegenerator遇EF Core版本不匹配

Fixing EF Core Version Mismatch Error with dotnet aspnet-codegenerator

Hey there! Let's work through that .NET Entity Framework Core version mismatch error you're facing when running the Razor Page generator command for the Contoso University tutorial. I've dealt with this exact hiccup before, so here are actionable steps to resolve it:

1. Ensure Consistent EF Core Package Versions in Your Project

Open your ContosoUniversity.csproj file and double-check that all Microsoft.EntityFrameworkCore.* packages (runtime and tools) have identical version numbers. For example, if you're using EF Core 6.0.22, make sure Microsoft.EntityFrameworkCore, Microsoft.EntityFrameworkCore.Tools, Microsoft.EntityFrameworkCore.Design, and any other related packages all use 6.0.22—mixing 6.x and 7.x versions is a common cause of this error.

2. Sync Global Tools with Project EF Core Version

The global dotnet-aspnet-codegenerator and dotnet-ef tools might be running a different version than your project's EF Core:

  • First, check your installed global tool versions:
    dotnet tool list --global
    
  • If the versions don't match your project's EF Core version, uninstall the old tools:
    dotnet tool uninstall --global dotnet-aspnet-codegenerator
    dotnet tool uninstall --global dotnet-ef
    
  • Install the matching version (replace <your-project-ef-version> with your actual version, e.g., 6.0.22):
    dotnet tool install --global dotnet-aspnet-codegenerator --version <your-project-ef-version>
    dotnet tool install --global dotnet-ef --version <your-project-ef-version>
    

3. Clean, Restore, and Rebuild Your Project

Cached build artifacts can sometimes cause version conflicts. Run these commands in your project directory:

dotnet clean
dotnet restore
dotnet build

After this, try re-running your original aspnet-codegenerator command again.

4. Explicitly Specify Tool Version in the Command

If the above steps don't work, you can force the generator to use a specific version directly in your command. Add the --tool-version flag with your project's EF Core version:

C:\dev\vs\ContosoUniversity\ContosoUniversity>dotnet aspnet-codegenerator razorpage -m Student -dc SchoolContext -udl -outDir Pages\Students --referenceScriptLibraries --tool-version <your-project-ef-version>

内容的提问来源于stack exchange,提问作者mo_maat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 10:19:13