【发布时间】:2020-02-15 22:32:56
【问题描述】:
我有一个 .NET Core 2.2 项目,正在尝试设置 EF 迁移。
运行时:
dotnet ef 迁移添加 init --verbose
我收到以下错误:
为提供者寻找设计时服务 'Microsoft.EntityFrameworkCore.SqlServer'... 使用设计时 来自提供者“Microsoft.EntityFrameworkCore.SqlServer”的服务。 查找程序集“myproject-api”引用的设计时服务。不 找到了引用的设计时服务。发现 程序集“myproject-api”中的 IDesignTimeServices 实现...否 找到了设计时服务。 System.IO.FileNotFoundException: 无法加载文件或程序集 'myproject, Culture=neutral, PublicKeyToken=null'。系统找不到指定的文件。
这是我的 csproj 文件:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.4" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.4" />
</ItemGroup>
</Project>
编辑,这是我的 Program.cs
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseKestrel()
.UseUrls("http://localhost:5004")
.UseStartup<Startup>();
}
【问题讨论】:
-
您能构建您的项目或解决方案吗?
-
您如何设置您的应用程序以使用 dbcontext?我个人只使用过两个命令:使用 nuget 包管理器:“add-migration”和“update-database”
-
是的,我可以构建我的项目@BijayYadav
-
我之前没有为这个项目使用迁移@JohanHerstad,我一直在手动进行数据库更新
-
为了更好地了解您的项目设置,您能否发布您的数据库上下文定义以及启动文件。一开始尝试在迁移命令中指定您的数据库上下文:
dotnet ef migrations add init --context <dbcontextfile>
标签: c# .net-core entity-framework-core