【C#-sqlSugar-sqlite】在Windows从源码编译构建System.Data.SQLite.dll的方法

sqlSugar从git上拉下来就能编译、跑测试,非常方便。但是,如果你想了解原理,从源码编译System.Data.SQLite是必不可少的,否则的话open()这种地方调试都进不去。

那么如何编译System.Data.SQLite呢?

它使用Fossil,你要先创建两个文件夹D:\SQLiteRepositories和D:\SQLiteSource

然后类似这样

复制代码
fossil clone https://system.data.sqlite.org/ D:\SQLiteRepositories\sds.fossil

输出类似这样就成功了

Round-trips: 76 Artifacts sent: 0 received: 31804

Clone done, wire bytes sent: 20466 received: 512407584 remote: 194.195.208.62

Rebuilding repository meta-data...

100.0% complete...

Extra delta compression... 8 deltas save 22,850 bytes

Vacuuming the database...

project-id: xxx

server-id: xxx

这样拉下来是单个文件,你还需要这样

复制代码
cd D:\SQLiteSource
fossil open D:\SQLiteRepositories\sds.fossil

这样才相当于git clone了。

切到跟自己的sqlSugar兼容的版本,比如

复制代码
fossil update release-1.0.102.0

然后编译。编译时会有一些坑,比如vs版本问题,强制签名什么的,我也不是很懂,总之把我能跑的贴在这里。

复制代码
cd d:\SQLiteSource; C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe System.Data.SQLite\System.Data.SQLite.2015.csproj /p:Configuration=Debug /p:Platform=Win32 /p:SignAssembly=false /p:DelaySign=false 

Start-Process -FilePath 'C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe' -ArgumentList 'SQLite.Interop\SQLite.Interop.2015.vcxproj', '/p:Configuration=Debug', '/p:Platform=Win32' -Wait -NoNewWindow 

Start-Process -FilePath 'C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe' -ArgumentList 'SQLite.Interop\SQLite.Interop.2015.vcxproj', '/p:Configuration=DebugNativeOnly', '/p:Platform=Win32' -Wait -NoNewWindow 

最后,把输出的System.Data.SQLite.dll等文件粘贴到Src\Asp.Net\SqlSugar\References\下面,把旧的命名为System.Data.SQLite.dll.bak就可以了。

再次在open()按F11,就可以直接跳转到D:\SQLiteSource下的那些源文件里。

实际上,微软的C#/.NET提供了一个虚函数套,叫做System.Data(里面包含抽象类DbConnection等等),希望各个数据库都可以适配它,这样大家用C#的时候就会比较统一,那么果不其然sqlite官方真的就适配了它。再然后,sqlSugar.sqlite就是直接面向已经适配了System.Data的sqlite-C#进行编程。

相关推荐
22信通小白1 小时前
USRP初学者使用手册(基础配置及bug记录)——Windows+MATLAB
windows·matlab·bug
胡斌附体1 小时前
Windows 打包方式与 exe图标说明
windows·electron·exe·package·build·nsis
weixin_408099671 小时前
图片去水印 API 接口实战:网站如何实现自动去水印(Python / PHP / C#)
图像处理·人工智能·python·c#·php·api·图片去水印
小江的记录本2 小时前
【Linux】《Linux常用命令汇总表》
linux·运维·服务器·前端·windows·后端·macos
:mnong4 小时前
Superpowers 项目设计分析
java·c语言·c++·python·c#·php·skills
我是唐青枫4 小时前
C#.NET 分布式事务 深入解析:TCC、Saga、Outbox 与落地取舍
分布式·c#·.net
追烽少年x4 小时前
Windows API中线程异步API简介
windows
私人珍藏库4 小时前
[Windows] 绘画工具 Krita v5.3.1
人工智能·windows·媒体·工具·软件·多功能
CSharp精选营5 小时前
.NET 8 性能优化实战:让你的应用起飞
性能优化·c#·.net·技术干货
tumeng07119 小时前
Node.JS 版本管理工具 Fnm 安装及配置(Windows)
windows·node.js