10

My project solution is currently having three projects:

  1. MyProject, which is my main startup project (using .NET Framework 4.7) - WPF, UI specfic,
  2. MyProject.Core - class library (.NET Standard 2.0) - holding the models, and all of the 'behind the scenes' data
  3. MyProject.Relational - class library (.NET Standard 2.0) - responsible for processing and saving the database specific informations

Project 1 (main) has set a reference to project 2 and 3.

For the project 3 I have installed a NuGet dependency of Microsoft.EntityFrameworkCore.Sqlite (2.0.3).

Now, when I finally want to make use of project 3 and call it's method, the following exception is being thrown:

System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.EntityFrameworkCore, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified.

This, of course is a missing DLL file - no entity framework DLL's are being copied to the app Debug directory.

Why is that? Is this intended behaviour? Do I have to install the dependency of Microsoft.EntityFrameworkCore.Sqlite for project 1 as well? Pretty pointless to me, referencing the same dependency to project that is making no use of it.

What have I tried:

Using Visual Studio 2017.

RA.
  • 969
  • 13
  • 36
  • Is Microsoft.EntityFrameworkCore in your project references? – TheGeneral May 23 '18 at 06:34
  • Btw i just tried this nuget and it works for me, maybe update your nugets, or do a update-package -reinstall on your project – TheGeneral May 23 '18 at 06:35
  • @TheGeneral Yes it is https://i.imgur.com/h8Bhfnd.png. It is referenced in project `3`. `update-package -reinstall` did not help. The problem is that those DLL files are not being copied into my app directory. – RA. May 23 '18 at 06:46
  • can you send an image of your CSPROJ file for MyProject.Relational? – Judy007 May 23 '18 at 07:01
  • Hmm, very insteresting. I have looked into CSPROJ file and added following line `PackageReference` to the `PropertyGroup` and now everything works like a charm... (I found the line in my old project's CSPROJ file). I have no idea why this line wasn't added into my CSPROJ automatically... If someone could explain this and post an answer, that would be great! – RA. May 23 '18 at 07:13
  • @DonaldDuck: I'd recommend you add that as an answer, for the poor person that comes across your question ;) – npinti May 23 '18 at 09:15
  • 1
    @DonaldDuck, I knew it was CSPROJ :) – Judy007 May 24 '18 at 00:24
  • @joey Yeah, you gave me an idea :) – RA. May 24 '18 at 13:26

1 Answers1

10

Solved this by adding the following line into my .csproj file:

<RestoreProjectStyle>PackageReference</RestoreProjectStyle>

Specifically to the PropertyGroup group.

Not sure why it makes such difference, if anyone could explain and post in the comment it would be great. Any additional informations I will add to this answer.

RA.
  • 969
  • 13
  • 36
  • 2
    Thanks for this, as it pointed me in the right direction. A more detailed explanation is here: https://www.hanselman.com/blog/ReferencingNETStandardAssembliesFromBothNETCoreAndNETFramework.aspx – Tim M. Apr 20 '19 at 15:35
  • After using this magic fix I had to install package again as nuget tool forget it installed. – SerG Sep 03 '20 at 20:28
  • This needs a thousand upvotes. You must get rid of packages.config files. Migrate .NET Standard libraries from packages.config to PackageReference. I then had to add win in main project to make NuGet work correctly. – llessurt Aug 17 '23 at 21:03