.NET Standard 2.0核心项目中MvvmCross SQLite插件选型咨询
Great question—this is a common pain point when working with MvvmCross and .NET Standard, especially since the old plugin ecosystem has shifted significantly over the years. Let’s break down the current landscape and your best options:
First, the context on deprecated plugins
The Cirrious.MvvmCross.Plugins.Sqlite package you’re searching for is completely deprecated—MvvmCross stopped maintaining these old "Cirrious-branded" plugins back around version 5, which is why it doesn’t show up in NuGet anymore. Similarly, the sqlite-pcl-net mentioned in v5 docs was a transitional package that never gained full MvvmCross integration, so it’s not a viable long-term solution.
Current MvvmCross + SQLite approach
MvvmCross no longer ships with official SQLite plugins. Instead, the team recommends integrating standard, cross-platform SQLite libraries via MvvmCross’s built-in dependency injection (DI) system. This gives you more flexibility and ensures compatibility with .NET Standard 2.0.
Top options for your .NET Standard 2.0 project
Here are the two most reliable, widely used solutions:
Primary Recommendation:
sqlite-net-pcl+ MvvmCross DI
This is the de facto standard for SQLite with MvvmCross today. Thesqlite-net-pclpackage (maintained by Frank Krueger) is fully compatible with .NET Standard 2.0, offers a lightweight ORM, and plays nicely with MvvmCross’s MVVM pattern.- Install the NuGet package:
Install-Package sqlite-net-pcl - Register your SQLite connection in MvvmCross’s
Setupclass to make it available via DI:protected override void InitializeFirstChance() { base.InitializeFirstChance(); // Adjust the database path based on your target platform (this works for desktop/mobile) var dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "your_app.db3"); Mvx.IoCProvider.RegisterSingleton<ISQLiteConnection>(() => new SQLiteConnection(dbPath)); } - Inject the connection into your ViewModels or services via constructor injection, just like any other MvvmCross dependency:
public class MyViewModel : MvxViewModel { private readonly ISQLiteConnection _db; public MyViewModel(ISQLiteConnection db) { _db = db; // Use _db to create tables, query data, etc. } }
- Install the NuGet package:
Alternative:
Microsoft.Data.Sqlite+ MvvmCross
If you prefer a more ADO.NET-style approach or need deeper integration with Microsoft’s ecosystem,Microsoft.Data.Sqliteis a solid choice. It also supports .NET Standard 2.0 and works well with MvvmCross’s DI.- Install the NuGet package:
Install-Package Microsoft.Data.Sqlite - Register the connection in
Setup:protected override void InitializeFirstChance() { base.InitializeFirstChance(); var connectionString = new SqliteConnectionStringBuilder { DataSource = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "your_app.db3") }.ToString(); Mvx.IoCProvider.RegisterSingleton<SqliteConnection>(() => new SqliteConnection(connectionString)); } - Inject and use it in your ViewModels/services as needed—this is ideal if you’re writing lots of raw SQL queries.
- Install the NuGet package:
Why to avoid other "SQLite-PCL" packages
Most generic SQLite-PCL packages aren’t optimized for MvvmCross, and many lack proper .NET Standard support or active maintenance. Stick to the two options above for stability and compatibility.
In short: MvvmCross has moved away from proprietary plugins to embrace standard libraries, which is great for .NET Standard projects. sqlite-net-pcl is your best bet for most MVVM scenarios, thanks to its ORM features and seamless DI integration.
内容的提问来源于stack exchange,提问作者Agat

