EntityFrameworkCore.​Sqlite in a Full .Net Framework xUnit Class Library

Georg Dangl by Georg Dangl in DotNet Thursday, June 29, 2017

Thursday, June 29, 2017

Posted in Testing

While migrating a still project.json based project to Visual Studio 2017s *.csproj format, an integration tests project gave me a bit of a headache:

It's been a class library project that used the Microsoft.AspNetCore.TestHost package for integration testing API calls. Since I wanted to make use of a relational database for data integrity and validation, I chose to use Microsoft.EntityFrameworkCore.Sqlite as database provider. After migration, however, I got a lot of System.DllNotFoundException telling me that sqlite3.dll could not be loaded.

I have been unable to find any real cause for the issue, but it's got something to do with the SQLite NuGet package dlls not being copied to the output directory when targeting the full .Net Framework in a class library. Kinda, sorta, somehow. It comes up in issues where people couldn't run dotnet ef CLI commands without a startup project.

 Luckily, I could fix it:

  • I made a copySQLiteDlls.ps1 script that copied the required Dlls in a Dependencies folder in the solution root

  • I added the Dlls to be included in the output on compilation in the *.csproj file:

Just make sure to run the first script after a package restore or before running your tests and you should be fine. There should now be an x64 and x86 folder in your output directory containing the sqlite3.dll files.

Happy integration!


Share this post


comments powered by Disqus

About me

Hi, my name's George! I love coding and blogging about it. I focus on all things around .Net, Web Development and DevOps.

DanglIT

Need a consultant for BIM, GAEB or Software Development?

Contact me at [email protected], +49 (173) 56 45 689 or visit my professional page!

Dangl.Blog();
// Just 💗 Coding

Social Links