2017-09-17 113 views
0

當我嘗試添加遷移我得到這個錯誤:添加遷移Exeception

PM> add-migration RestrictPromotionContentAndTitle 
    System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. 
     at BrightInfo.Infrastructure.Settings.DbAudit.AuditDbContext..ctor(String connString) 
     at BrightInfo.Infrastructure.Settings.BrightInfoContext..ctor(Boolean proxyCreationEnabled, Boolean lazyLoadingEnabled) in C:\Projects\BrightInfo\BrightInfo.Infrastructure.Settings\BrightInfoContext.cs:line 124 
     at BrightInfo.Infrastructure.Settings.BrightInfoContext..ctor() in C:\Projects\BrightInfo\BrightInfo.Infrastructure.Settings\BrightInfoContext.cs:line 113 
     --- End of inner exception stack trace --- 
     at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) 
     at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) 
     at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) 
     at System.Activator.CreateInstance(Type type, Boolean nonPublic) 
     at System.Activator.CreateInstance(Type type) 
     at System.Data.Entity.Infrastructure.DbContextInfo.<CreateActivator>b__0() 
     at System.Data.Entity.Infrastructure.DbContextInfo..ctor(Type contextType, DbProviderInfo modelProviderInfo, AppConfig config, DbConnectionInfo connectionInfo) 
     at System.Data.Entity.Infrastructure.DbContextInfo..ctor(Type contextType) 
     at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext) 
     at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration) 
     at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.GetMigrator() 
     at System.Data.Entity.Migrations.Design.ToolingFacade.GetPendingMigrationsRunner.RunCore() 
     at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run() 
    Exception has been thrown by the target of an invocation. 

誰不知道如何解決這個問題? 在此先感謝。

P.S:我忘了,當我切換到包管理控制檯我得到這個錯誤信息說:

Unable to find type [NuGet.PackageManager]. Make sure that the assembly that contains this type is loaded. 
At C:\Projects\BrightInfo\packages\T4Scaffolding.Core.1.0.0\tools\init.ps1:4 char:5 
+ if ([NuGet.PackageManager].Assembly.GetName().Version -lt 1.4) 
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidOperation: (NuGet.PackageManager:TypeName) [], RuntimeException 
    + FullyQualifiedErrorId : TypeNotFound 

是否有人知道如何解決它? 謝謝。

+0

你做出的最後一項改變是什麼? – ASpirin

+0

這是我第一次嘗試在Visual Studio 2017中遷移。 –

回答

0

似乎你沒有在你的項目中正確引用dll。

無法加載文件或程序集「Microsoft.Build.Framework,Version = 15.1.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a」或其某個依賴項。該系統找不到指定的文件。 at ...

如果您可以添加適當的dll和clean解決方案,重新構建解決方案,然後再試一次,您應該成功執行。如果進一步的錯誤仍然存​​在,請發佈您的遷移細節以更好地理解和幫助您。

HTH

+0

是的,我已閱讀有關此問題https://developercommunity.visualstudio.com/content/problem/25424/error-running-entity-framework-6- code-first-migrat.html與相關鏈接,我已將它們更改爲絕對路徑。 –

+0

但它沒有幫助。 –