我用以下.csproj创建了一个类库项目:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp1.1</TargetFramework> </PropertyGroup> <ItemGroup> <packagereference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" /> <packagereference Include="Microsoft.EntityFrameworkCore.sqlServer" Version="1.1.1" /> <packagereference Include="Microsoft.EntityFrameworkCore.sqlserver.Design" Version="1.1.1" /> <packagereference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.0" /> </ItemGroup> </Project>
运行命令时:
Add-Migration -Name Test -Context TestContext
我收到以下错误:
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.EntityFrameworkCore.Design,Culture=neutral,PublicKeyToken=null'. The system cannot find the file specified. File name: 'Microsoft.EntityFrameworkCore.Design,PublicKeyToken=null' at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName,String codeBase,Evidence assemblySecurity,RuntimeAssembly locationHint,StackCrawlMark& stackMark,IntPtr pPrivHostBinder,Boolean throwOnFileNotFound,Boolean forIntrospection,Boolean suppressSecurityChecks,IntPtr ptrLoadContextBinder) at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef,RuntimeAssembly reqAssembly,IntPtr ptrLoadContextBinder) at System.Reflection.Assembly.Load(AssemblyName assemblyRef) at Microsoft.EntityFrameworkCore.Tools.ReflectionoperationExecutor..ctor(String assembly,String startupAssembly,String projectDir,String contentRootPath,String dataDirectory,String rootNamespace,String environment) at Microsoft.EntityFrameworkCore.Tools.Commands.ProjectCommandBase.CreateExecutor() at Microsoft.EntityFrameworkCore.Tools.Commands.MigrationsAddCommand.Execute() at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args) at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args) Could not load file or assembly 'Microsoft.EntityFrameworkCore.Design,PublicKeyToken=null'. The system cannot find the file specified.
但是,已经安装了Microsoft.EntityFrameworkCore.Design.
我正在使用Visual Studio Community 2017(VisualStudio / 15.0.0 26228.9)
我错过了什么?
解决方法
它在添加Microsoft.EntityFrameworkCore.Tools.DotNet并将dotnet工具的版本更改为1.0.0-msbuild2-final后工作,现在我的.csproj是:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp1.1</TargetFramework> </PropertyGroup> <ItemGroup> <packagereference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" /> <packagereference Include="Microsoft.EntityFrameworkCore.sqlServer" Version="1.1.1" /> <packagereference Include="Microsoft.EntityFrameworkCore.sqlserver.Design" Version="1.1.1" /> <packagereference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.0.0-msbuild2-final" /> <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0-msbuild2-final" /> </ItemGroup> </Project>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。