Thrift has an interface definition language (IDL), which is used to define a thrift service and structures. This interface is saved in a .thrift file and ran through the Thrift compiler to generate C#, Java, Perl or a code for dozen other languages.
A quick googling shows there is a MSBuild task to integrate the Thrift Compiler into a MSBuild, but I couldn’t find an example of how to use it.
Using the Thrift MSbuild Task
Below are the fairly straight-forward steps to use the Thrift MSBuild Task.
1. Create a Visual Studio Project, .Thrift file and import the Thrift library using nuGet.
2. Compile ThriftBuild into a DLL
Create a Class Library project.
Add references to:
Compile! This will output a .dll. In my eample it is named ThriftMSBuildTask.dll.
3. Add the Thrift MSBuild task to a project.
1. Unload and edit the project.
2. Make the following change to the unloaded project file.
<UsingTask AssemblyFile=".\Thrift\ThriftMSBuildTask.dll" TaskName="ThriftMSBuildTask.ThriftBuild" /> <Target Name="BeforeBuild"> <ThriftBuild OutputName=".\ThriftLib.dll" ThriftDefinitionDir=".\Thrift\" ThriftExecutable=".\Thrift\thrift-0.8.0.exe" ThriftLibrary="..\packages\Thrift.0.8.0.27874\lib\net35\Thrift.dll" /> </Target>
3. Compile the project.
4. Add a reference to the ThriftLib.dll. It will be located in the same folder as Thrift.dll.
5. Modify the .thrift IDL and compile away! The IDL generates the C# code before compiling the project. This will provide immediate feedback if the IDL has made a change which no longer compiles!
It takes very little time to hookup the thrift compiler to MSBuild. It is definitely worth doing if you are making regular changes to the Thrift IDL.
The ThriftBuild.cs code is not the greatest C# code and could use some love. There also needs to be a better location for distributing this MSBuild task. I might look at creating a nuGet package for it.
My sample code including the MSbuildTask.dll can be found here: