Reputation: 1309
I am following Julie Lerman's Getting Started with Entity Framework Core 2.0 tutorial. I have installed Microsoft.EntityFrameworkCore.SqlServer Version 2.0.2. When I try to run add-migration initial (Package Manager Console) in VS 2017 I am obtaining the below error :
System.IO.FileLoadException: Could not load file or assembly 'Microsoft.EntityFrameworkCore.SqlServer, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'Microsoft.EntityFrameworkCore.SqlServer, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
When I run dotnet --version i get 2.1.3.
Can anybody help me rectify this error.
Screenshot :
Thanks in Advance.
Upvotes: 5
Views: 6351
Reputation: 36
Following the very same Pluralsight video, I ran into this same problem. After running:
PM> install-package Microsoft.EntityFrameworkCore.SqlServer
with the default project set to SomeUI
I was able to get the add-migration initial
to run without any problems at all, after doing so.
Upvotes: 1
Reputation: 1309
I know the following is not an exact answer to my own question. But rather than waiting to somebody answer how to solve it in VS 2017 ( Windows ) I am taking a Terminal Approach on my Mac and using dotnet cli to recreate the solution (Julie Lerman hope you won't send your favorite Samurai for a battle :P)
Note: Steps below is for Mac. Windows users having SQl Server Installed can Skip Step 1.
Step 1 : Install Docker and Pull MSSQL Image
a. Install docker and pull latest mssql image for linux using :
sudo docker pull microsoft/mssql-server-linux
b. Start the docker image using :
sudo docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=
<ComplexPassword>' -p 1433:1433 -d microsoft/mssql-server-linux
c. Optional. Install sql-cli using npm install -g sql-cli
. Now you can connect to Sql Server running on Docker using mssql -s 127.0.0.1 -u sa -p.
Step 2 : Create .sln, .csproj and add references using dotnet cli
dotnet new sln -n SamuraiApp
Create Data and Domain class Library Projects using : dotnet new classlib -n SamuraiApp.Data
and dotnet new classlib -n SamuraiApp.Domain
Create and Empty ASP.NET Core Project using dotnet new web -n SamuraiApp.UI
Add Entity Frmaework Core to Data ClassLibrary using : cd SamuraiApp.Data
and dotnet add package Microsoft.EntityFrameworkCore.SqlServer
Add Entity Framework Core Design to UI Project Using : cd SamuraiApp.UI/
and dotnet add package Microsoft.EntityFrameworkCore.Design
Run dotnet restore
Step 3: Add References
dotnet add SamuraiApp.Data reference SamuraiApp.Domain/SamuraiApp.Domain.csproj
to add Domain as a reference to Data.dotnet add SamuraiApp.UI reference SamuraiApp.Domain/SamuraiApp.Domain.csproj
to add Domain as reference to UI.dotnet add SamuraiApp.UI reference SamuraiApp.Data/SamuraiApp.Data.csproj
to add Data as reference to UI.Execute below commands to add all three projects to solution:
dotnet sln add SamuraiApp.Data/SamuraiApp.Data.csproj dotnet sln add SamuraiApp.Domain/SamuraiApp.Domain.csproj dotnet sln add SamuraiApp.UI/SamuraiApp.UI.csproj
Open SamuraiApp.Data.csproj in your favorite text editor and add the following:
<ItemGroup>
<DotNetCliToolReference
Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup>
To enable dotnet ef.
Step 4 : Write Domain Classes, DataContext class and add migration cd into SamuraiApp.Data folder and execute the below command to add initial migration:
dotnet ef migrations add Initial --startup-project ../SamuraiApp.UI
Hope it helps to somebody. But still In windows using VS 2017 I am facing issues and would hope somebody will help me solve it.
Thanks :)
Upvotes: 0