MVVMCross SQLite社区插件不会添加到Xamarin Studio项目中

时间:2013-12-29 08:27:23

标签: sqlite plugins xamarin.ios mvvmcross

我正在构建一个MVVMCross项目,最初用于iOS,但目的是扩展到Android。我正在使用Xamarin Studio创建应用程序,并且我将PCL设置为我的Core,具有针对UI的iOS特定项目,根据文档中的示例和优秀的N + 1视频。但是现在我遇到了障碍:我正在尝试从NuGet包中添加SQLite到项目中,并且根据建议我尝试添加社区插件而不是“旧”版本,但是我收到以下错误当我这样做时:


        ------- Installing...MvvmCross.Community.Plugin.Sqlite 3.0.13 -------
    Attempting to resolve dependency 'MvvmCross.HotTuna.CrossCore (≥ 3.0.13)'.
    Attempting to resolve dependency 'MvvmCross.PortableSupport (≥ 3.0.14)'.
    Adding 'MvvmCross.Community.Plugin.Sqlite 3.0.13' to ShimanoSocial.Core.
    Could not install package 'MvvmCross.Community.Plugin.Sqlite 3.0.13'. You are trying to install this package into a project that targets 'portable-net45+wp80+win+MonoAndroid10+MonoTouch10', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
    System.InvalidOperationException: Could not install package 'MvvmCross.Community.Plugin.Sqlite 3.0.13'. You are trying to install this package into a project that targets 'portable-net45+wp80+win+MonoAndroid10+MonoTouch10', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
      at NuGet.ProjectManager.ExtractPackageFilesToProject (IPackage package) [0x00000] in :0 
      at NuGet.ProjectManager.AddPackageReferenceToProject (IPackage package) [0x00000] in :0 
      at NuGet.ProjectManager.Execute (NuGet.PackageOperation operation) [0x00000] in :0 
      at NuGet.ProjectManager.Execute (IPackage package, IPackageOperationResolver resolver) [0x00000] in :0 
      at NuGet.ProjectManager.AddPackageReference (IPackage package, Boolean ignoreDependencies, Boolean allowPrereleaseVersions) [0x00000] in :0 
      at NuGet.ProjectManager.AddPackageReference (System.String packageId, NuGet.SemanticVersion version, Boolean ignoreDependencies, Boolean allowPrereleaseVersions) [0x00000] in :0 
      at ICSharpCode.PackageManagement.SharpDevelopPackageManager.AddPackageReference (IPackage package, Boolean ignoreDependencies, Boolean allowPrereleaseVersions) [0x00000] in :0 
      at ICSharpCode.PackageManagement.SharpDevelopPackageManager.InstallPackage (IPackage package, ICSharpCode.PackageManagement.InstallPackageAction installAction) [0x00000] in :0 
      at ICSharpCode.PackageManagement.PackageManagementProject.InstallPackage (IPackage package, ICSharpCode.PackageManagement.InstallPackageAction installAction) [0x00000] in :0 
      at ICSharpCode.PackageManagement.InstallPackageAction.ExecuteCore () [0x00000] in :0 
      at ICSharpCode.PackageManagement.ProcessPackageAction.Execute () [0x00000] in :0 
      at ICSharpCode.PackageManagement.PackageActionRunner.Run (IPackageAction action) [0x00000] in :0 
      at ICSharpCode.PackageManagement.PackageViewModel.InstallPackage (IEnumerable`1 packageOperations) [0x00000] in :0 
      at ICSharpCode.PackageManagement.PackageViewModel.InstallPackage () [0x00000] in :0 
      at ICSharpCode.PackageManagement.PackageViewModel.TryInstallingPackage () [0x00000] in :0 
    ==============================

我的项目使用配置文件78定位.NET 4.5 +,WP8,W8,Xamarin.Android和Xamarin.iOS。

我以前能够安装“旧的”SQLite MVVMCross插件,但不想这样做,因为它显然已被弃用,转而支持社区版。但是社区版将无法安装。

任何人都可以建议如何使这个工作?

非常感谢提前!

1 个答案:

答案 0 :(得分:1)

请勿使用此插件。

而是使用PCL nuget“sqlite.net pcl”。它具有跨平台的sqlite lib。您必须至少将nuget包添加到最终应用程序(ios / android)项目和Core项目。

http://www.nuget.org/packages/SQLite.Net-PCL/ 要么 https://www.nuget.org/packages/SQLite.Net.Async-PCL/用于异步版

使用示例:https://github.com/oysteinkrog/SQLite.Net-PCL

在每个平台的启动方法中,您必须在mvvmcross IOC中注册带有SQLitePlatformIOS实现的ISQLitePlatform接口。

Mvx.RegisterType<ISQLitePlatform, SQLitePlatformIOS>();    

然后,您可以使用mvvmcross IOC构建器创建SQLiteConnection的实例。

var sqlConnection = Mvx.IocConstruct<SQLiteConnection>("mydbpath");

或者如果您不想使用ioc,请在您的cross lib中创建一个静态属性,然后在每个平台项目的启动时分配它。

注意:不支持IOC方法,因为mvvmcross IocContruct当前不能有参数。