2016-12-01 70 views
1

我想创建一个新的ASP.net核心应用程序,但问题是,每个我建,我得到了以下错误消息的应用程序:System.IO.FileLoadException不匹配

PM> add-migration Init 
System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.Logging, Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) 
File name: 'Microsoft.Extensions.Logging, Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' 
    at Microsoft.EntityFrameworkCore.Design.Internal.StartupInvoker.ConfigureHostServices(IServiceCollection services) 
    at Microsoft.EntityFrameworkCore.Design.Internal.StartupInvoker.ConfigureServices() 
    at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations..ctor(IOperationReporter reporter, Assembly assembly, Assembly startupAssembly, String environment, String contentRootPath) 
    at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations..ctor(IOperationReporter reporter, Assembly assembly, Assembly startupAssembly, String environment, String projectDir, String contentRootPath, String rootNamespace) 
    at Microsoft.EntityFrameworkCore.Design.OperationExecutor.<>c__DisplayClass4_0.<.ctor>b__4() 
    at Microsoft.EntityFrameworkCore.Internal.LazyRef`1.get_Value() 
    at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType) 
    at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0() 
    at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action) 
Could not load file or assembly 'Microsoft.Extensions.Logging, Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) 

我GOOGLE了它,发现以下可能是错误。中Ref-DEF-不匹配 https://blogs.msdn.microsoft.com/junfeng/2004/03/25/the-located-assemblys-manifest-definition-with-name-xxx-dll-does-not-match-the-assembly-reference/

只有我的问题是,我无法找到一个解决这个问题。有没有人有想法?

我project.json是:

{ 
    "userSecretsId": "secret", 

    "runtimes": { 
    "win10-x64": {} 
    }, 

    "dependencies": { 
    "Microsoft.AspNetCore.Razor.Tools": { 
     "version": "1.0.0-preview2-final", 
     "type": "build" 
    }, 
    "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final", 
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { 
     "version": "1.0.0-preview2-final", 
     "type": "build" 
    }, 
    "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": { 
     "version": "1.0.0-preview2-final", 
     "type": "build" 
    }, 
    "Microsoft.ApplicationInsights.AspNetCore": "1.0.2", 
    "Microsoft.AspNetCore.Authentication.Cookies": "1.1.0", 
    "Microsoft.AspNetCore.Diagnostics": "1.1.0", 
    "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.1.0", 
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.1.0", 
    "Microsoft.AspNetCore.Mvc": "1.1.0", 
    "Microsoft.AspNetCore.Routing": "1.1.0", 
    "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0", 
    "Microsoft.AspNetCore.Server.Kestrel": "1.1.0", 
    "Microsoft.AspNetCore.StaticFiles": "1.1.0", 
    "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0", 
    "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0", 
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0", 
    "Microsoft.Extensions.Configuration.Json": "1.1.0", 
    "Microsoft.Extensions.Configuration.UserSecrets": "1.1.0", 
    "Microsoft.Extensions.Logging": "1.1.0", 
    "Microsoft.Extensions.Logging.Console": "1.1.0", 
    "Microsoft.Extensions.Logging.Debug": "1.1.0", 
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0", 
    "Microsoft.NETCore.App": "1.1.0", 
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.1.0" 
    }, 

    "tools": { 
    "BundlerMinifier.Core": "2.0.238", 
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final", 
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final", 
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final", 
    "Microsoft.Extensions.SecretManager.Tools": "1.0.0-preview2-final", 
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { 
     "version": "1.0.0-preview2-final", 
     "imports": [ 
     "portable-net45+win8" 
     ] 
    } 
    }, 

    "frameworks": { 
    "netcoreapp1.0": { 
     "imports": [ 
     "dotnet5.6", 
     "portable-net45+win8" 
     ] 
    } 
    }, 

    "buildOptions": { 
    "emitEntryPoint": true, 
    "preserveCompilationContext": true 
    }, 

    "runtimeOptions": { 
    "configProperties": { 
     "System.GC.Server": true 
    } 
    }, 

    "publishOptions": { 
    "include": [ 
     "wwwroot", 
     "**/*.cshtml", 
     "appsettings.json", 
     "web.config" 
    ] 
    }, 

    "scripts": { 
    "prepublish": [ "bower install", "dotnet bundle" ], 
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] 
    } 
} 
+0

显示你的project.json - 也许你是混合包版本 – Pawel

+0

我更新了我的project.json文章在它现在。你可能有一个想法? – StuiterSlurf

+1

内部框架根据[公告](https://blogs.msdn.microsoft.com/webdev/2016/11/16/announcing-asp-net-core-1-1/)应该是'netcoreapp1.1' )(不知道这是什么原因) –

回答

1

像丹尼尔J.G.说我需要更新我的project.json以下内容:

{ 
    "userSecretsId": "secret", 

    "runtimes": { 
    "win10-x64": {} 
    }, 

    "dependencies": { 
    "Microsoft.AspNetCore.Razor.Tools": { 
     "version": "1.0.0-preview2-final", 
     "type": "build" 
    }, 
    "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final", 
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { 
     "version": "1.0.0-preview2-final", 
     "type": "build" 
    }, 
    "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": { 
     "version": "1.0.0-preview2-final", 
     "type": "build" 
    }, 
    "Microsoft.ApplicationInsights.AspNetCore": "1.0.2", 
    "Microsoft.AspNetCore.Authentication.Cookies": "1.1.0", 
    "Microsoft.AspNetCore.Diagnostics": "1.1.0", 
    "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.1.0", 
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.1.0", 
    "Microsoft.AspNetCore.Mvc": "1.1.0", 
    "Microsoft.AspNetCore.Routing": "1.1.0", 
    "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0", 
    "Microsoft.AspNetCore.Server.Kestrel": "1.1.0", 
    "Microsoft.AspNetCore.StaticFiles": "1.1.0", 
    "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0", 
    "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0", 
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0", 
    "Microsoft.Extensions.Configuration.Json": "1.1.0", 
    "Microsoft.Extensions.Configuration.UserSecrets": "1.1.0", 
    "Microsoft.Extensions.Logging": "1.1.0", 
    "Microsoft.Extensions.Logging.Console": "1.1.0", 
    "Microsoft.Extensions.Logging.Debug": "1.1.0", 
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0", 
    "Microsoft.NETCore.App": "1.1.0", 
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.1.0" 
    }, 

    "tools": { 
    "BundlerMinifier.Core": "2.0.238", 
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final", 
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final", 
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final", 
    "Microsoft.Extensions.SecretManager.Tools": "1.0.0-preview2-final", 
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { 
     "version": "1.0.0-preview2-final", 
     "imports": [ 
     "portable-net45+win8" 
     ] 
    } 
    }, 

    "frameworks": { 
    "netcoreapp1.1": { 
     "imports": [ 
     "dotnet5.6", 
     "portable-net45+win8" 
     ] 
    } 
    }, 

    "buildOptions": { 
    "emitEntryPoint": true, 
    "preserveCompilationContext": true 
    }, 

    "runtimeOptions": { 
    "configProperties": { 
     "System.GC.Server": true 
    } 
    }, 

    "publishOptions": { 
    "include": [ 
     "wwwroot", 
     "**/*.cshtml", 
     "appsettings.json", 
     "web.config" 
    ] 
    }, 

    "scripts": { 
    "prepublish": [ "bower install", "dotnet bundle" ], 
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] 
    } 
} 

之后,我还需要指定我的deps.json。

PM> add-migration init 
The specified deps.json [C:\Users\ik_ro\Source\Repos\ProjectDotNetCoreTest\src\ProjectDotNetCoreTest\bin\Debug\netcoreapp1.1\ProjectDotNetCoreTest.deps.json] does not exist 
Process finished with non-zero exit code 
PM> add-migration init 
The specified framework 'Microsoft.NETCore.App', version '1.1.0' was not found. 
    - Check application dependencies and target a framework version installed at: 
    C:\Program Files\dotnet\shared\Microsoft.NETCore.App 
    - The following versions are installed: 
    1.0.1 
    - Alternatively, install the framework version '1.1.0'. 
Process finished with non-zero exit code 

,它搜索的位置是:

C:\Users\ik_ro\Source\Repos\ProjectDotNetCoreTest\src\ProjectDotNetCoreTest\bin\Debug\netcoreapp1.1\win10-x64 

但它需要的是:

C:\Users\ik_ro\Source\Repos\ProjectDotNetCoreTest\src\ProjectDotNetCoreTest\bin\Debug\netcoreapp1.1\win10-x64 

我复制和一切从win10-x64文件夹中粘贴到netcoreapp1.1夹。这解决了问题。