最近从EF Core 1.0迁移到EF Core 2.0,运行良好。今天,我添加了一个新表(代码优先),并使用以下命令将其添加到我的DbContext中:
public virtual DbSet<Foo> Foos { get; set; }当我用我的DbContext在一个单独的项目中运行迁移时(请记住,这之前都是有效的),迁移结束,但没有创建迁移文件。这一切都是在Core 2.0之前使用的:
http://paultechguy.blogspot.com/2017/04/entity-framework-core-migrating-and.html
PM> Add-Migration GradePremade -project Mfc.MfcRepositoryModel -verbose -context MfcDbContext -StartupProject web.xyz
Using project 'class.xyz\Mfc.MfcRepositoryModel'.
Using startup project 'web.xyz'.
Build started...
Build succeeded.
C:\Program Files\dotnet\dotnet.exe exec --depsfile C:\development\xyz\web.xyz\bin\Debug\netcoreapp2.0\web.xyz.deps.json --additionalprobingpath C:\Users\pcarver\.nuget\packages --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig C:\development\xyz\web.xyz\bin\Debug\netcoreapp2.0\web.xyz.runtimeconfig.json "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.entityframeworkcore.tools\2.0.0\tools\netcoreapp2.0\ef.dll" migrations add GradePremade --json --context MfcDbContext --verbose --no-color --prefix-output --assembly C:\development\xyz\web.xyz\bin\Debug\netcoreapp2.0\Mfc.MfcRepositoryModel.dll --startup-assembly C:\development\xyz\web.xyz\bin\Debug\netcoreapp2.0\web.xyz.dll --project-dir C:\development\xyz\class.xyz\Mfc.MfcRepositoryModel --root-namespace Mfc.MfcRepositoryModel
Using assembly 'Mfc.MfcRepositoryModel'.
Using startup assembly 'web.xyz'.
Using application base 'C:\development\xyz\web.xyz\bin\Debug\netcoreapp2.0'.
Using working directory 'C:\development\xyz\web.xyz'.
Using root namespace 'Mfc.MfcRepositoryModel'.
Using project directory 'C:\development\xyz\class.xyz\Mfc.MfcRepositoryModel'.
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider...
Finding BuildWebHost method...
No BuildWebHost method was found on type 'xyz.Program'.
No application service provider was found.
Finding DbContext classes in the project...
Found DbContext 'ApplicationDbContext'.
Found DbContext 'MfcDbContext'.
Using DbContext factory 'MfcContextFactory'.
Using context 'MfcDbContext'.
Finding design-time services for provider 'Microsoft.EntityFrameworkCore.SqlServer'...
Using design-time services from provider 'Microsoft.EntityFrameworkCore.SqlServer'.
Finding IDesignTimeServices implementations in assembly 'web.xyz'...
No design-time services were found.没有对我来说显而易见的错误,也没有创建迁移文件。我已经做了一次Remove-Migration,以开始干净的工作,但仍然没有效果。
发布于 2017-12-20 22:41:45
我不得不将一个项目标记为启动项目。
发布于 2018-01-16 18:35:04
.NET核心类库中存在一个问题。成功的解决方法是将以下内容放入Model项目的csproj文件中:
<PropertyGroup>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
</PropertyGroup>发布于 2017-08-24 09:06:38
您需要将Program类更新为如下所示
public class Program
{
public static void Main(string[] args)
{
var host = BuildWebHost(args);
host.Run();
}
// Tools will use this to get application services
public static IWebHost BuildWebHost(string[] args) =>
new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
}https://stackoverflow.com/questions/45851229
复制相似问题