问题描述
我的计算机最近决定对我死机,因此在其他各种复苏方法失败后,我决定恢复为Window的自动备份之一。备份是在我安装Syncfusion Blazor之前进行的,但是那时我还没有遇到我目前遇到的错误。当我在VS中加载项目时,“错误列表”迅速填充了以下消息:
软件包Microsoft.AspNetCore.Components 3.1.4与netcoreapp3.1(.NETCoreApp,Version = v3.1)不兼容。软件包Microsoft.AspNetCore.Components 3.1.4不支持任何目标框架
'IServiceCollection'不包含'AddDbContext'的定义,并且找不到可以接受的扩展方法'AddDbContext'接受类型为'IServiceCollection'的第一个参数(您是否缺少using指令或程序集引用?)>
由于我运行的代码与以前相同,所以我不确定是什么导致了这些错误。我试过修复VS,卸载和重新安装软件包以及“还原Nuget软件包”选项。不幸的是,Intellisense也没有帮助。
编辑:这是我的Startup.cs
文件:
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using ThinBlueLieB.Identity;
using ThinBlueLieB.Data;
using DataAccessLibrary.DataAccess;
using Pomelo.EntityFrameworkCore.MysqL.Infrastructure;
using Syncfusion.Blazor; //error- count not be found
using ThinBlueLieB.Helper;
namespace ThinBlueLieB
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
// For more @R_85_4045@ion on how to configure your application,visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<UserDbContext>(options => //error no deFinition
options.UseMysqL(Configuration.GetConnectionString("UserDB"),MysqLOptions => MysqLOptions
.ServerVersion(new Version(8,18),ServerType.MysqL)));
services.AddDefaultIdentity<IdentityUser>(options => //error no deFinition
options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<UserDbContext>();
services.AddOptions();
services.Configure<ConnectionStrings>(Configuration.GetSection("ConnectionStrings"));
services.AddScoped<ISearches,Searches>();
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddScoped<AuthenticationStateProvider,RevalidatingIdentityAuthenticationStateProvider<IdentityUser>>();
services.AddSingleton<WeatherForecastService>();
services.AddSingleton<IDataAccess,DataAccess>();
services.AddSyncfusionBlazor(); //error - no deFinition
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app,IWebHostEnvironment env)
{ //error-no deFinition
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("MzA2NDMyQDMxMzgyZTMyMmUzMFVGc2cvTmU0d0NMbWZiRjBkZEl2WGlzU3lHdnBIcTNYRHYzYk5OSHrftDA9");
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage(); //error- no deFinition
app.UsebrowserLink();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios,see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
}
}
}
解决方法
重新安装Visual Studio,删除所有软件包并在CLI中弄乱之后,我找到了修复程序。虽然我不确定这是否对遇到此问题的每个人都有用,但我所做的只是注释,构建和取消注释csproj文件中的所有<PackageReference/>
标签。对于其他面临相同问题的人,如果那对您不起作用,请尝试:
- Restoring packages
- Repairing Visual Studio
- 解决了我的问题后,我收到一条通知,告知您以前的csproj和当前的csproj编码不同,因此请确保您的编码匹配。对我来说,修复后,它变成了UTF-8,而不是西欧(Windows)