2018-03-12 00:38:07 +01:00
# TDLib C# example
This is an example of building TDLib with `C++/CLI` support and an example of TDLib usage from C#.
## Building TDLib
* Download and install Microsoft Visual Studio 2015 or later.
2018-07-08 02:18:46 +02:00
* Download and install [CMake ](https://cmake.org/download/ ); choose "Add CMake to the system PATH" option while installing.
2023-05-10 15:36:52 +02:00
* Install `gperf` , `zlib` , and `openssl` using [vcpkg ](https://github.com/Microsoft/vcpkg#quick-start ):
2018-03-12 00:38:07 +01:00
```
2023-05-10 15:36:52 +02:00
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
2023-11-26 09:10:08 +01:00
git checkout cd5e746ec203c8c3c61647e0886a8df8c1e78e41
2023-05-10 15:36:52 +02:00
.\bootstrap-vcpkg.bat
2021-09-15 09:00:34 +02:00
.\vcpkg.exe install gperf:x64-windows gperf:x86-windows openssl:x64-windows openssl:x86-windows zlib:x64-windows zlib:x86-windows
2018-03-12 00:38:07 +01:00
```
2023-03-07 12:46:43 +01:00
* (Optional. For XML documentation generation.) Download [PHP ](https://windows.php.net/download ). Add the path to php.exe to the PATH environment variable.
2018-03-16 22:26:27 +01:00
* Build `TDLib` with CMake enabling `.NET` support and specifying correct path to `vcpkg` toolchain file:
2018-03-12 00:38:07 +01:00
```
cd < path to TDLib sources > /example/csharp
mkdir build
cd build
2020-02-03 23:36:52 +01:00
cmake -A Win32 -DTD_ENABLE_DOTNET=ON -DCMAKE_TOOLCHAIN_FILE=< path to vcpkg > /scripts/buildsystems/vcpkg.cmake ../../..
cmake --build . --config Release
cmake --build . --config Debug
cd ..
mkdir build64
cd build64
cmake -A x64 -DTD_ENABLE_DOTNET=ON -DCMAKE_TOOLCHAIN_FILE=< path to vcpkg > /scripts/buildsystems/vcpkg.cmake ../../..
2018-03-12 00:38:07 +01:00
cmake --build . --config Release
cmake --build . --config Debug
```
## Example of usage
After `TDLib` is built you can open and run TdExample project.
It contains a simple console C# application with implementation of authorization and message sending.
2020-12-05 20:10:58 +01:00
Just open it with Visual Studio 2015 or later and run.
2018-03-13 19:14:07 +01:00
2023-01-02 13:38:04 +01:00
Also, see TdExample.csproj for example of including TDLib in C# project with all native shared library dependencies.