0.环境准备,我使用的VS版本是17.9.4,SDK版本是10.0.22621.0,最好不要用太老的版本

1.去下载Python,git,cmake这三个工具,然后在D盘根目录新建TBuild文件夹,里面再建Libraries和ThirdParty这两个文件夹
下载地址:
Python3.10:https://www.python.org/downloads/
Git:https://git-scm.com/download/win
cmake2.21及以后版本:https://cmake.org/download/

2.把这三个工具放进ThirdParty这个文件夹内

3.去区域设置里勾上UTF-8编码,搜索框里输区域就能找到

4.在cmd中进入TBuild文件夹下,使用git获取telegram,命令如下:
git clone --recursive https://github.com/telegramdesktop/tdesktop.git
下载好后会自动新建一个tdesktop的文件夹
网络不好的话可以设置代理:
cmd代理:set http_proxy=http://127.0.0.1:7890/1234; set https_proxy=http://127.0.0.1:7890/1234; 端口号根据实际填写
git代理:git config --global http.proxy localhost:1234; git config --global https.proxy localhost:1234
也可以去git地址下载源码

5.打开vs的X86编辑器,我编译的是32位的telegram,如果编译64位可能有些步骤会有区别

6.进入图中的文件夹,运行win.bat命令,然后就会自动下载所需的工具和第三方库,一共有28个


7.过程中可能会遇到下载失败的情况,这个时候会出现r重构,a全部重构,s跳过,p打印,q退出这几种选项,如果对自己编译能力不是特别有信心,那就不要自己去编译,选择重构。因为有些组件前后存在联系,所以最好按顺序编译。
成功了的话就会显示SKIPPING,程序会自动跳过,需要手动输命令一般都是编译失败了,不过自己手动编译了的话也需要输命令跳过

8.全部编译成功就是下图这个样子

9.然后进入图中的文件夹进行构建,输入以下命令,命令中的api_id和api_hash是官方提供的示例,自己有的话可以替换成自己的
configure.bat -D TDESKTOP_API_ID=17349 -D TDESKTOP_API_HASH=344583e45741c457fe1862106095a5eb

10.构建成功的话会在out文件夹里出现sln文件,点击就能进入vs22里开始编译了

10.编译成功的样子


11.可能会遇到C1128这个错误,在报错的项目内的图中位置加上 /bigobj就可以了



如果还遇到了其他问题,欢迎在评论区讨论
参考文章:tdesktop/docs/building-win.md at dev · telegramdesktop/tdesktop · GitHub