Visual Studios每次尝试用视图构建控制器时都会失败



我有一个.Net core 5项目,我已经完成了大约2/3的工作。我不得不在数据库中添加一个新表来跟踪客户端的附加表单。我现在已经添加了该表的模型,并将其添加到我的上下文中:

型号:

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
#nullable disable
namespace EnvApp.Models.DB
{
[Table("Type_Two")]
public class TypeTwo
{
[Key]
public long ID { get; set; }
[MaxLength(50), Required]
public string State_Project_Number { get; set; }
[MaxLength(50)]
public string Federal_Project_Number { get; set; }
[MaxLength(50)]
public string Name { get; set; }
[MaxLength(50)]
public string Route_Number { get; set; }
public string County { get; set; }
[Required]
public string Category { get; set; }
public int ADT_Existing { get; set; }
public int ADT_Projected { get; set; }
[MaxLength(100)]
public string Coordinates { get; set; }
[Required]
public bool Federal_Nexus { get; set; }
public string Existing_Conditions { get; set; }
public string Preferred_Alternatives { get; set; }
public string Other_Alternatives { get; set; }
public string Public_Involvement { get; set; }
public bool Right_of_Way { get; set; }
[MaxLength(100)]
public string Right_of_Way_Comments { get; set; }
public bool Federal_Land { get; set; }
[MaxLength(100)]
public string Federal_Land_Comments { get; set; }
public bool Maintenance_of_Traffic { get; set; }
[MaxLength(100)]
public string Maintenance_of_Traffic_Comment { get; set; }
public bool Public_Controversy { get; set; }
[MaxLength(100)]
public string Public_Controversy_Comment { get; set; }
public bool History { get; set; }
[MaxLength(100)]
public string History_Comment { get; set; }
public bool H_Adverse_Effect { get; set; }
[MaxLength(100)]
public string H_Adverse_Effect_Comment { get; set; }
public bool Archaeology { get; set; }
[MaxLength(100)]
public string Archaeology_Comment { get; set; }
public bool A_Adverse_Effect { get; set; }
[MaxLength(100)]
public string A_Adverse_Effect_Comment { get; set; }
public bool US_Forest_Service { get; set; }
[MaxLength(100)]
public string US_Forest_Service_Comment { get; set; }
public bool US_Army_Corps_Eng { get; set; }
[MaxLength(100)]
public string US_Army_Corps_Eng_Comment { get; set; }
public bool National_Park_Service { get; set; }
[MaxLength(100)]
public string National_Park_Service_Comment { get; set; }
public bool Wild_Scenic_River { get; set; }
[MaxLength(100)]
public string Wild_Scenic_River_Comment { get; set; }
public bool National_River { get; set; }
[MaxLength(100)]
public string National_River_Comment { get; set; }
public bool National_Wildlife_Refuge { get; set; }
[MaxLength(100)]
public string National_Wildlife_Refuge_Comment { get; set; }
public bool State_Park { get; set; }
[MaxLength(100)]
public string State_Park_Comment { get; set; }
public bool State_Wildlife_Management_Area { get; set; }
[MaxLength(100)]
public string State_Wildlife_Management_Area_Comment { get; set; }
public bool Other_Park { get; set; }
[MaxLength(100)]
public string Other_Park_Comment { get; set; }
public bool Historic_Property { get; set; }
[MaxLength(100)]
public string Historic_Property_Comment { get; set; }
public bool Park_Recreational { get; set; }
[MaxLength(100)]
public string Park_Recreational_Comment { get; set; }
public bool DE_Minimis { get; set; }
[MaxLength(100)]
public string DE_Minimis_Comment { get; set; }
public bool Programmatic { get; set; }
[MaxLength(100)]
public string Prog_Comment { get; set; }
public bool D_Individual { get; set; }
[MaxLength(100)]
public string D_Individual_Comment { get; set; }
public bool LWCFA { get; set; }
[MaxLength(100)]
public string LWCFA_Comment { get; set; }
public bool Temp_Change { get; set; }
[MaxLength(100)]
public string Temp_Change_Comment { get; set; }
public bool Conversion_of_Property { get; set; }
[MaxLength(100)]
public string Conversion_of_Property_Comment { get; set; }
public bool US_Fish_Wildlife { get; set; }
[MaxLength(100)]
public string US_Fish_Wildlife_Comment { get; set; }
public bool Formal_Consultation { get; set; }
[MaxLength(100)]
public string Formal_Consultation_Comment { get; set; }
public bool Division_Natural_Resources { get; set; }
[MaxLength(100)]
public string Division_Natural_Resources_Comment { get; set; }
public bool Floodplain_Enchroachment { get; set; }
[MaxLength(100)]
public string Floodplain_Enchroachment_Comment { get; set; }
public bool Farmland_Involvment { get; set; }
[MaxLength(100)]
public string Farmland_Involvment_Comment { get; set; }
public bool FourZeroFour { get; set; }
[MaxLength(100)]
public string FourZeroFour_Comment { get; set; }
public bool Nationwide { get; set; }
[MaxLength(100)]
public string Nationwide_Comment { get; set; }
public bool F_Individual { get; set; }
[MaxLength(100)]
public string F_Individual_Comment { get; set; }
public bool USCG_Sec_9 { get; set; }
[MaxLength(100)]
public string USCG_Sec_9_Comment { get; set; }
public bool USCG_Sec_10 { get; set; }
[MaxLength(100)]
public string USCG_Sec_10_Comment { get; set; }
public bool Fed_Special_Use_Permit { get; set; }
[MaxLength(100)]
public string Fed_Special_Use_Permit_Comment { get; set; }
public bool Noise { get; set; }
[MaxLength(100)]
public string Noise_Comment { get; set; }
public bool Air_Quality { get; set; }
[MaxLength(100)]
public string Air_Quality_Comment { get; set; }
public bool Haz_Waste { get; set; }
[MaxLength(100)]
public string Haz_Waste_Comment { get; set; }
public bool Airport { get; set; }
[MaxLength(100)]
public string Airport_Comment { get; set; }
public bool Mussel_Survey { get; set; }
[MaxLength(100)]
public string Mussel_Survey_Comment { get; set; }
public bool Mussel_Relocation { get; set; }
[MaxLength(100)]
public string Mussel_Relocation_Comment { get; set; }
public bool WVDOH_Special_Prov { get; set; }
[MaxLength(100)]
public string WVDOH_Special_Prov_Comment { get; set; }
[MaxLength(20)]
public string Perepared_By { get; set; }
[MaxLength(20)]
public string WV_DOH_Approved_By { get; set; }
[Required]
public bool FHWA_Approval { get; set; }
[MaxLength(20)]
public string FHWA_Approved_By { get; set; }
[MaxLength(20)]
public string Add_User { get; set; }
public DateTime Date_Added { get; set; }
}
}

上下文:

using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
#nullable disable
namespace EnvApp.Models.DB
{
public partial class Natural_ResourcesContext : DbContext
{
public Natural_ResourcesContext()
{
}
public Natural_ResourcesContext(DbContextOptions<Natural_ResourcesContext> options)
: base(options)
{
}
public virtual DbSet<NR_User> NR_Users { get; set; }
public virtual DbSet<Project_Screen> Project_Screen { get; set; }
public virtual DbSet<TypeOne> TypeOne { get; set; }
public virtual DbSet<TypeTwo> TypeTwo { get; set; }
} 
}

当我试图为TypeTwo模型构建一个带有视图的控制器时,我收到了一条错误消息:

Error
There was an error running the selected code generator: 'Package restore failed. Rolling back package changes for 'EnvApp'.'

这就是我得到的所有信息。

如何获取更多信息来诊断问题?如果这是一个常见问题,那么解决方法是什么?

如果我尝试更新NuGet软件包管理器解决方案中的所有软件包,我会收到以下错误消息:

Restoring packages for C:Userse096752DocumentsCole's Git ReposELCCEnvAppEnvApp.csproj...
NU1701: Package 'ExpressiveAnnotations 2.9.6' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net5.0'. This package may not be fully compatible with your project.
NU1701: Package 'Newtonsoft.Json 4.5.11' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net5.0'. This package may not be fully compatible with your project.
NU1202: Package Microsoft.EntityFrameworkCore.SqlServer 6.0.1 is not compatible with net5.0 (.NETCoreApp,Version=v5.0). Package Microsoft.EntityFrameworkCore.SqlServer 6.0.1 supports: net6.0 (.NETCoreApp,Version=v6.0)
NU1202: Package Microsoft.EntityFrameworkCore.Design 6.0.1 is not compatible with net5.0 (.NETCoreApp,Version=v5.0). Package Microsoft.EntityFrameworkCore.Design 6.0.1 supports: net6.0 (.NETCoreApp,Version=v6.0)
NU1202: Package Microsoft.EntityFrameworkCore.Tools 6.0.1 is not compatible with net5.0 (.NETCoreApp,Version=v5.0). Package Microsoft.EntityFrameworkCore.Tools 6.0.1 supports: net6.0 (.NETCoreApp,Version=v6.0)
NU1202: Package Microsoft.VisualStudio.Web.CodeGeneration.Design 6.0.1 is not compatible with net5.0 (.NETCoreApp,Version=v5.0). Package Microsoft.VisualStudio.Web.CodeGeneration.Design 6.0.1 supports: net6.0 (.NETCoreApp,Version=v6.0)
Package restore failed. Rolling back package changes for 'EnvApp'.

我有这个问题,并搜索了很多关于这个的信息。此解决方案可能会有所帮助:您可以执行以下步骤:

1-VS工具

2-选项

3-Nuget Package Manager

4-通用

5-清除所有Nuget缓存。

你需要更改target.net核心,如果你用最新版本更新你的VS(例如VS 2017 15.3(,这是可能的

这个参考资料也可以帮助你。

最新更新