【发布时间】:2017-09-03 22:16:19
【问题描述】:
我升级到VS2017 15.3.3,但仍在使用code first 方法处理ASP.NET MVC Core 1.1.1 项目。当我从官方 ASP.NET 团队(更适合 ASP.NET Core 2.0)关注this tutorial 时,当我运行以下Package Manager 命令(来自教程)时,我遇到了兼容性错误(v2.0 vs v1.1):
Install-Package Microsoft.EntityFrameworkCore.SqlServer
所以,我决定将-version 1.1.1作为参数添加到上述命令中,如下所示,它运行成功:
Install-Package Microsoft.EntityFrameworkCore.SqlServer -version 1.1.1
我对上述教程中的其他两个相关的PM 命令做了同样的事情,一切都运行良好。但是现在,当我运行以下 PM 命令时,出现以下错误:
PM> add-migration MyFirstMigration -context BloggingContext
错误
无法加载文件或程序集 'Microsoft.EntityFrameworkCore.SqlServer, Version=1.1.2.0
.csproj 文件
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
<UserSecretsId>aspnet-MVC_IndvUserAccts_Test-B2520DA6-BE8D-42EE-806D-366F7C4C2E77</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.2" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.1" />
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="1.0.1" />
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />
</ItemGroup>
</Project>
【问题讨论】:
-
请您在您的 csproj 中发布所有的程序集引用。
-
@mvermef 当然。根据您的要求,我刚刚添加了
.csproj文件内容。 -
运行
add-migration somemigrationname -Context BloggingContext得到那个错误?您指示的添加迁移实际上会出错.. install-package Microsoft.EntityFrameworkCore.SqlServer -Version 1.1.2 应该是正确的。 BloggingContext 也是唯一的吗? -
@mvermef 1. 是的,实际上我正在运行
add-migration MyFirstMigration -Context BloggingContext(感谢您指出这一点 - 我刚刚在我的帖子中更正了这一点)。 2. 由于应用程序使用个人用户帐户身份验证模式,因此如果选择身份验证模式,则其他 DbContext 是 Visual Studio 默认创建的ApplicationDbContext。
标签: asp.net-core entity-framework-core