I upgraded my "legacy" ASP.NET Core project (it's about 1 year old) to .NET Core 1.1. I think I was successful although it took a little wrangling. Certainly I can compile and run the project fine, and the EF subsystem communicates with the DB fine, so I figured I was in the clear. I even pushed a release or two.
But then I made a model change and I want to do a migration. So I run
dotnet ef migrations list --context MyContext
in preparation for the migration and I get an exception:
System.IO.FileNotFoundException: Could not find file '/MyProject/project.json'.
File name: '/MyProject/project.json'
But of course there isn't a project.json anymore. There's a new csproj instead. So this confuses me and leads me to suspect a versioning or package version/dependency issue. I've spent a couple hours troubleshooting it's gotten me nowhere. Please advise.
Contents of csproj:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.0-preview4-final" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.0" />
<PackageReference Include="Npgsql" Version="3.2.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="1.1.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.1.0-preview4-final" />
</ItemGroup>
</Project>
dotnet --version: 1.0.0-rc3-004530 (from SDK installer found here)
Database Provider: Npgsql.EntityFrameworkCore.PostgreSQL
Operating system: MacOS
IDE: VSCode
I am having this issue as well. Why would the latest versions of the ef tools expect a project.json when the dotnet new command using the latest聽SDK tools not create one? Is this a defect or is there some other version of the tools that we should be using when working with csproj? Given that the full release of VS2017 is just a few days away it would be nice if this聽could be cleared up... so much documentation still refers to the now defunct project.json. Any advice would be appreciated.
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.1.0-preview4-final" />
Above package still uses project.json system. Please use 1.0.0-msbuild3-final package version which is for csproj based solution.
Confirmed.
Translation:
Microsoft.EntityFrameworkCore.Tools from 1.1.0-preview4-final to 1.0.0-msbuild3-finalMicrosoft.EntityFrameworkCore.Tools.DotNet from 1.1.0-preview4-final to 1.0.0-msbuild3-finaldotnet restore on the projectdotnet ef migrations list --context MyContextEF command succeeds now.
Thanks for the quick response. I have made the changes that you suggest and now I have the following error...
Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I'm not sure exactly what that means and I'm not the expert in this forum, but if I had to guess, you are now going to need to troubleshoot non-EF related project dependency issues. My project doesn't use System.Diagnostics.DiagnosticSource and thus I am not experienced with it.
@GZidar - Can you share your csproj file?
This is the csproj file聽
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<AssemblyName>WebAPI.Database</AssemblyName>
<PackageId>WebAPI.Database</PackageId>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.0.0-msbuild3-final" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0-msbuild3-final" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WebAPI.Shared\WebAPI.Shared.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
and this is the csproj file of the project that聽is being referenced
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<AssemblyName>WebAPI.Shared</AssemblyName>
<PackageId>WebAPI.Shared</PackageId>
</PropertyGroup>
</Project>
I don't know if this helps but it seems that this is happening to others as well...
https://www.benday.com/2017/02/14/walkthrough-entity-framework-core-1-1-with-migrations/
@GZidar you're hitting the external issue dotnet/corefx#15031 which should be fixed in 1.1.1 (coming soon)
@bricelam Thanks for the聽heads up...聽glad to know I was not going crazy. Is there a timeframe for 1.1.1聽being released?
Any day now. 馃槃 We've got a candidate feed on MyGet if you're eager to test it out.
@bricelam I have updated my project with the new NuGet packages and I am sorry to report that the problem聽still persists.聽I also note that there is no聽Microsoft.EntityFrameworkCore.Tools.DotNet package in that patch set so I am assuming聽that I still need to refer to the 1.0.0-msbuild3-final - perhaps that is the reason I still have the problem.
my current csproj file is below:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<AssemblyName>WebAPI.Database</AssemblyName>
<PackageId>WebAPI.Database</PackageId>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0-msbuild3-final" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WebAPI.Shared\WebAPI.Shared.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Oh I think you'll need a new .NET Core SDK too. It's the thing that's adding the reference to System.Diagnostics.DiagnosticsSource in the first place.
@bricelam I have installed the new SDK (dotnet --version reports as 1.0.0-rc4-004913) and after running dotnet restore and then dotnet build I still get the error with the dotnet ef migrations commands :-(
I'm not able to reproduce this anymore locally using the 1.1.1 feed and the latest SDK (reports 1.0.0). @GZidar Could you try again with the latest .NET Core SDK 1.0.0 (candidate)? If you're still hitting issues, can you follow up on dotnet/corefx#15031?
Most helpful comment
Confirmed.
Translation:
Microsoft.EntityFrameworkCore.Toolsfrom1.1.0-preview4-finalto1.0.0-msbuild3-finalMicrosoft.EntityFrameworkCore.Tools.DotNetfrom1.1.0-preview4-finalto1.0.0-msbuild3-finaldotnet restoreon the projectdotnet ef migrations list --context MyContextEF command succeeds now.