Christian
Christian

Reputation: 1027

Copy NuGet Boost DLL to automatically to the Output directory

I am using several Boost libraries in my C++ project. The libraries are acquired through NuGet packages, e.g. the Boost Thread library boost_thread.

Compiling and linking works without any changes to the project properties. But debugging and running the application fails due to missing DLLs in the output directory.

One solution is to use the post build step copying the required DLLs. This is described at other places, e.g. how to make visual studio copy dll to output directory?.

This is an example for the required copy command in the Debug configuration:

xcopy /F /Y "$(SolutionDir)\packages\boost_regex-vc100.1.58.0.0\lib\native\address-model-32\lib\boost_regex-vc100-mt-gd-1_58.dll" "$(OutDir)"

The Project is Visual Studio 2010 project. But the IDE actually used is Visual Studio 2013.

But is there a better way to achieve this?

Upvotes: 3

Views: 840

Answers (1)

Chris Bechette
Chris Bechette

Reputation: 51

I used MSBuild's copy task for this exact purpose:

<PropertyGroup Condition="'$(Configuration)'=='Debug'">
  <BoostRT>-gd</BoostRT>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release' Or '$(Configuration)'=='Release_withPDB'">
  <BoostRT></BoostRT>
</PropertyGroup>
<ItemGroup>
<BoostDlls Include="..\packages\boost_log-vc120.1.59.0.0\lib\native\address-model-$(PlatformArchitecture)\lib\boost_log-vc120-mt$(BoostRT)-1_59.dll;
  ..\packages\boost_thread-vc120.1.59.0.0\lib\native\address-model-$(PlatformArchitecture)\lib\boost_thread-vc120-mt$(BoostRT)-1_59.dll;
  ..\packages\boost_system-vc120.1.59.0.0\lib\native\address-model-$(PlatformArchitecture)\lib\boost_system-vc120-mt$(BoostRT)-1_59.dll;
  ..\packages\boost_chrono-vc120.1.59.0.0\lib\native\address-model-$(PlatformArchitecture)\lib\boost_chrono-vc120-mt$(BoostRT)-1_59.dll;
  ..\packages\boost_date_time-vc120.1.59.0.0\lib\native\address-model-$(PlatformArchitecture)\lib\boost_date_time-vc120-mt$(BoostRT)-1_59.dll;
  ..\packages\boost_filesystem-vc120.1.59.0.0\lib\native\address-model-$(PlatformArchitecture)\lib\boost_filesystem-vc120-mt$(BoostRT)-1_59.dll" />
</ItemGroup>
<Target Name="CopyFiles" AfterTargets="Build">
  <Copy SourceFiles="@(BoostDlls)" DestinationFolder="$(OutDir)" />
</Target>

Hardcoding the boost lib version (1.59) is not awesome but other than that it works well.

Upvotes: 1

Related Questions