Search code examples
visual-studiobuildmsbuildvcpkg

vcpkg: code execution cannot proceed because dll was not found


enter image description here

I installed protobuf with vcpkg.

This happens when I build/redeploy and no c++ files where changed (i.e. no c++ linking). Changes in Xaml, and hlsl files for example.

I can fix this by touching any c++ file and rebuilding, but this is ruining my DX.

I have been naively copying the dll to the build output but this has just stopped working. I think the execute after/execute before default options changed may have changed in visual studio.

Steps to reproduce

Install protobuf with vcpkg (also have vcpkg integrated with vs)

Generate .h and .cpp files using the protobuf compiler vcpkg\packages\protobuf_x64-windows\tools\protobuf\protoc.exe https://protobuf.dev/getting-started/cpptutorial/

Include them in a project created with the Blank App WinUI 3 c++ template.

Can someone help me set up a build command to copy the dll across after everything else has finished?


Solution

  • I think you can use a post-build event! so in visual studio right click on your project and select Properties,then in Build Events tab, select Post-Build Event section and enter the command to copy the DLL file to the desired output directory!

    something like this :

    xcopy /y "$(PathToDLL)\protobuf.dll" "$(TargetDir)"
    

    don't forget to replace $(PathToDLL)\protobuf.dll and $(TargetDir) with the actual path!!!

    now save the project properties, and that's it.

    good luck !