gpt4 book ai didi

c# - 命名空间 'Microsoft 中不存在类型或命名空间名称 'EntityFrameworkCore'

转载 作者:行者123 更新时间:2023-12-01 22:10:45 24 4
gpt4 key购买 nike

我尝试为 Visual Studio 2017 执行 Razor ContosoUniversity(最初在 ContsoObserve 中重命名)并出现错误我的 .csproj 是

<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Utils" Version="2.0.1" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="Microsoft.NETCore.App" Version="2.0.4" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.1" />
</ItemGroup>
</Project>

我在 NuGet 中安装了所有这些包

当我

dotnet aspnet-codegenerator razorpage -m Student -dc SchoolContext -udl -outDir Pages\Students --referenceScriptLibraries

得到

Build FAILED. Data\SchoolContext.cs(5,17): error CS0234: The type or namespace name 'EntityFrameworkCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Pages\About.cshtml.cs(5,32): error CS0234: The type or namespace name 'RazorPages' does not exist in the namespace 'Microsoft.AspNetCore.Mvc' (are you missing an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Pages\Contact.cshtml.cs(5,32): error CS0234: The type or namespace name 'RazorPages' does not exist in the namespace 'Microsoft.AspNetCore.Mvc' (are you missing an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Pages\Error.cshtml.cs(6,32): error CS0234: The type or namespace name 'RazorPages' does not exist in the namespace 'Microsoft.AspNetCore.Mvc' (are you missing an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Pages\Index.cshtml.cs(6,32): error CS0234: The type or namespace name 'RazorPages' does not exist in the namespace 'Microsoft.AspNetCore.Mvc' (are you missing an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Program.cs(7,28): error CS0234: The type or namespace name 'Hosting' does not exist in the namespace 'Microsoft.AspNetCore' (are you missing an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Program.cs(8,28): error CS0234: The type or namespace name 'Configuration' does not exist in the namespace 'Microsoft.Extensions' (are you missing an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Program.cs(9,28): error CS0234: The type or namespace name 'Logging' does not exist in the namespace 'Microsoft.Extensions' (are you missing an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Startup.cs(5,28): error CS0234: The type or namespace name 'Builder' does not exist in the namespace 'Microsoft.AspNetCore' (are you missing an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Startup.cs(6,28): error CS0234: The type or namespace name 'Hosting' does not exist in the namespace 'Microsoft.AspNetCore' (are you missing an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Startup.cs(7,28): error CS0234: The type or namespace name 'Configuration' does not exist in the namespace 'Microsoft.Extensions' (are you missing an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Startup.cs(10,17): error CS0234: The type or namespace name 'EntityFrameworkCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Pages\About.cshtml.cs(9,31): error CS0246: The type or namespace name 'PageModel' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Program.cs(39,23): error CS0246: The type or namespace name 'IWebHost' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Data\SchoolContext.cs(10,34): error CS0246: The type or namespace name 'DbContext' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Startup.cs(21,16): error CS0246: The type or namespace name 'IConfiguration' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Pages\Contact.cshtml.cs(9,33): error CS0246: The type or namespace name 'PageModel' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Startup.cs(33,31): error CS0246: The type or namespace name 'IApplicationBuilder' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Startup.cs(33,56): error CS0246: The type or namespace name 'IHostingEnvironment' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Data\SchoolContext.cs(16,16): error CS0246: The type or namespace name 'DbSet<>' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Startup.cs(16,24): error CS0246: The type or namespace name 'IConfiguration' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Pages\Error.cshtml.cs(10,31): error CS0246: The type or namespace name 'PageModel' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Data\SchoolContext.cs(17,16): error CS0246: The type or namespace name 'DbSet<>' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Data\SchoolContext.cs(18,16): error CS0246: The type or namespace name 'DbSet<>' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Data\SchoolContext.cs(20,49): error CS0246: The type or namespace name 'ModelBuilder' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Data\SchoolContext.cs(20,33): error CS0115: 'SchoolContext.OnModelCreating(ModelBuilder)': no suitable method found to override [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Pages\Index.cshtml.cs(10,31): error CS0246: The type or namespace name 'PageModel' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Data\SchoolContext.cs(12,30): error CS0246: The type or namespace name 'DbContextOptions<>' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] 0 Warning(s) 28 Error(s) I try unload and reload project. Same result.

我补充 错误计数减少

Build FAILED.

Data\SchoolContext.cs(5,17): error CS0234: The type or namespace name 'EntityFrameworkCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Pages\About.cshtml.cs(5,32): error CS0234: The type or namespace name 'RazorPages' does not exist in the namespace 'Microsoft.AspNetCore.Mvc' (are you missing an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Pages\Contact.cshtml.cs(5,32): error CS0234: The type or namespace name 'RazorPages' does not exist in the namespace 'Microsoft.AspNetCore.Mvc' (are you missing an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Pages\Error.cshtml.cs(6,32): error CS0234: The type or namespace name 'RazorPages' does not exist in the namespace 'Microsoft.AspNetCore.Mvc' (are you missing an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Pages\Index.cshtml.cs(6,32): error CS0234: The type or namespace name 'RazorPages' does not exist in the namespace 'Microsoft.AspNetCore.Mvc' (are you missing an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Startup.cs(10,17): error CS0234: The type or namespace name 'EntityFrameworkCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Pages\About.cshtml.cs(9,31): error CS0246: The type or namespace name 'PageModel' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Data\SchoolContext.cs(10,34): error CS0246: The type or namespace name 'DbContext' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Pages\Contact.cshtml.cs(9,33): error CS0246: The type or namespace name 'PageModel' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Pages\Error.cshtml.cs(10,31): error CS0246: The type or namespace name 'PageModel' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Data\SchoolContext.cs(16,16): error CS0246: The type or namespace name 'DbSet<>' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Pages\Index.cshtml.cs(10,31): error CS0246: The type or namespace name 'PageModel' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Data\SchoolContext.cs(17,16): error CS0246: The type or namespace name 'DbSet<>' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Data\SchoolContext.cs(18,16): error CS0246: The type or namespace name 'DbSet<>' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Data\SchoolContext.cs(20,49): error CS0246: The type or namespace name 'ModelBuilder' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Data\SchoolContext.cs(20,33): error CS0115: 'SchoolContext.OnModelCreating(ModelBuilder)': no suitable method found to override [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] Data\SchoolContext.cs(12,30): error CS0246: The type or namespace name 'DbContextOptions<>' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\STR\source\repos\ContosoObserve\ContosoObserve\ContosoObserve.csproj] 0 Warning(s)

最佳答案

将您的包引用更改为 Microsoft.AspNetCore.All(当前版本为 2.0.3)。这将包括 Entity Framework(加上您需要的内容)。

此外,不要在 PackageReference 元素上使用 Update,请使用 Include

关于c# - 命名空间 'Microsoft 中不存在类型或命名空间名称 'EntityFrameworkCore',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48098261/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com