2

最近、EF Core 1.0からEF Core 2.0に移行され、正常に動作します。 、移行(これはすべての前に働いていた覚えている)私は、マイグレーションを実行すると、別のプロジェクトで私のDbContextと、Entity Framework Core 2.0 Add-Migrationは移行ファイルを作成しません

public virtual DbSet<Foo> Foos { get; set; } 

:今日、私は(コード-最初の)新しいテーブルを追加して、私のDbContextにこれを追加しました移行ファイルは作成されませんでした。

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. 

私には明白なようではありませんエラー、および作成した無移行ファイルを:これは、すべての使用前のコア2.0に取り組んでいました。私はClean-Startを行うためにRemove-Migrationをやったことがありますが、まだWorkieはありません。

+0

、私は自分のデータベースと再実行アドインの移行の名前を変更しました。まったく同じ結果。 – user2737646

+0

解決方法を見つけましたか?私はまったく同じ問題を抱えています。 – Peter

答えて

1

私はスタートアッププロジェクトとしてプロジェクトをマークしなければなりませんでした。

0

あなたは、あなたがと同じように、あなたの移行プロジェクトからすべてのIDesignTimeDbContextFactory<TContext>実装を削除し、スタートアップクラスでのごConfigureServices方法であなたのDbContextを登録し、この

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(); 
} 
+0

私のWebアプリケーションのProgram.csにはこれが既にあります。私は別のクラスライブラリリポジトリにProgram.csも持っています。注意私は、作業リポジトリを持つ別のクラスライブラリを取得するために私が従った最初のステップのリンクに言及しました。これはEF Core 2.0とVS 2017 15.xの前に正常に機能しました。 – user2737646

+0

@ user2737646 .NetCore 1.xまたは.NetCore 2.0を使用していますか? – Abdi

+0

私は.NetCore 2.0、VS 2017 15.3、EF Core 2.0を使用しています – user2737646

0

のように見えるためにあなたのProgramクラスを更新する必要がありますアプリケーションの実行時に登録します。

その後、いつものようにマイグレーションコマンドを実行してください。これは数時間の頭痛の後に私のために働いていました。

-1

私が含まれるように.csprojファイル内のランタイムバージョンを更新しようとした:PropertyGroupタグで

<RuntimeFrameworkVersion>2.0.3</RuntimeFrameworkVersion> 

を。それは私のために働いた。

参照:Russell Seamer's Solution

2

.NET Coreクラスライブラリ内に問題があります。成功した回避策はModelプロジェクトのcsprojファイルに次のように置くことです:にやにや笑いのために

<PropertyGroup> 
    <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> 
</PropertyGroup> 
+1

シンプルで簡潔な - 私のために働いた! – Mike

+1

私は受け入れられたとマークすることはできません、それは私の質問ではなかった、私は単にあなたの答えが大好き! – Mike

関連する問題