将NuGet Boost DLL复制到Output目录

时间:2015-06-24 16:30:06

标签: c++ visual-studio-2010 boost dll nuget

我在我的C ++项目中使用了几个Boost库。这些库是通过NuGet包获得的,例如Boost线程库boost_thread

编译和链接无需更改项目属性即可工作。但是由于输出目录中缺少DLL,调试和运行应用程序失败。

一种解决方案是使用post build步骤复制所需的DLL。这在其他地方描述,例如how to make visual studio copy dll to output directory?

这是Debug配置中所需复制命令的示例:

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)"

该项目是Visual Studio 2010项目。但实际使用的IDE是Visual Studio 2013。

但有没有更好的方法来实现这一目标?

1 个答案:

答案 0 :(得分:1)

为了这个目的,我使用了MSBuild的复制任务:

<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>

对boost lib版本(1.59)进行硬编码并不是很棒,但除此之外它运行良好。

相关问题