Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 如何使SqLite在发布时在Windows 10中工作_C_Wpf_Sqlite - Fatal编程技术网

C 如何使SqLite在发布时在Windows 10中工作

C 如何使SqLite在发布时在Windows 10中工作,c,wpf,sqlite,C,Wpf,Sqlite,有一个使用Microsoft的经典应用程序.Entity Framework Core.Sqlite试图通过Windows 10部署发布应用程序,并引发异常:DllNotFoundException:无法加载DLL“e_sqlite3”:找不到指定的模块。(来自HRESULT的异常:0x8007007E) 尝试将e_sqlite3库添加到“Windows应用程序打包项目”中,最终出现异常:SQLite错误14:“无法打开数据库文件”,首先使用EF核心代码 我尝试了在互联网上找到的不同解决方案,但

有一个使用Microsoft的经典应用程序.Entity Framework Core.Sqlite试图通过Windows 10部署发布应用程序,并引发异常:DllNotFoundException:无法加载DLL“e_sqlite3”:找不到指定的模块。(来自HRESULT的异常:0x8007007E)

尝试将e_sqlite3库添加到“Windows应用程序打包项目”中,最终出现异常:SQLite错误14:“无法打开数据库文件”,首先使用EF核心代码

我尝试了在互联网上找到的不同解决方案,但没有一个我不适合的

发展环境:
Windows 10、Visual Studio 2017、Microsoft.EntityFrameworkCore.Sqlite 2.2.1.0和Microsoft.Data.Sqlite 2.2.1.0这是我如何解决这两个问题的

第一个问题是本地e_sqlite3.dll文件没有复制到包项目的输出中。包项目在Microsoft.DesktopBridge.targets中具有MSBuild逻辑,该逻辑正在调用其每个引用项目(例如WPF项目)的GetCopyToOutputDirectoryItems目标。由于e_sqlite3.dll文件通过NuGet包包含在引用的项目中,因此包含它们的方式不会导致GetCopyToOutputDirectoryItems目标拾取它们。我通过向WPF项目添加以下代码来解决此问题:

  <Target Name="IncludeNativeBinariesAsOutput" BeforeTargets="GetCopyToOutputDirectoryItems">
    <ItemGroup>
      <Content Include="$(OutputPath)\x64\e_sqlite3.dll">
        <Link>x64\e_sqlite3.dll</Link>
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      </Content>
      <Content Include="$(OutputPath)\x86\e_sqlite3.dll">
        <Link>x86\e_sqlite3.dll</Link>
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      </Content>
    </ItemGroup>

    <AssignTargetPath Files="@(Content)" RootFolder="$(MSBuildProjectDirectory)">
      <Output TaskParameter="AssignedFiles" ItemName="ContentWithTargetPath" />
    </AssignTargetPath>
  </Target>

您是否尝试在系统上安装sqlite(请参阅:)了?没有,因为WPF应用程序本身工作得很好。但是,当你在Windows10下创建一个发布包时,会遇到类似的问题:(我遇到了完全相同的问题。有什么解决方案吗?
AppDomain.CurrentDomain.SetData("DataDirectory", ApplicationData.Current.LocalFolder.Path);