Search code examples
f#nugetapache-kafkavisual-studio-2017paket

RdKafka setup not finding/recognizing librdkafka in Visual Studio


Issue: RdKafka setup is not finding/recognizing librdkafka in Visual Studio 15

Context:
In order to get started with RdKafka in visual studio 15, I ran the generic paket+nuget setup command (via powershell): paket add nuget rdkafka
After this, I see RdKafka has been installed successfully in my solutions package location. I also see a librdkafka package present.
Adding RdKafka as a reference in my solution works as well (I can't add the librdkafka dlls due to an error message from the IDE).
However, trying to run anything using librdkafka leads to a library not found.

What I've tried:

  • Removing rdkafka completely and paket reinstalling/updating/restoring
  • Cleaning + re-building the solution in IDE
  • Moving the librdkafka package around/including it in path

All the above to no success

Any suggestions on how to proceed?


Solution

  • So, it turns out someone else on my team figured out how to make this work, though admittedly it's a little bit of a hack. VS allows for pre-build events (Found by right clicking on your project > Properties > Build Events > Edit Pre-Build). And in there I dropped in the following:

    {xcopy /y /d /f "$(ProjectDir)..\packages\RdKafka.Internal.librdkafka\runtimes\win7-x64\native*.*" "$(TargetDir)"}

    And just like that, it works. The explanation for the above is that we pull the native dlls that cannot be referenced directly by copying them into our projects target directory just before the build is done. Hopefully, this helps some future folks, who don't consider rewriting the library into an referable form, like I did.