在 post 构建脚本中获取链接器设置

Getting linker settings in post build script

我正在尝试编写一个 post 构建脚本,它应该将所有必需的 dlls 复制到 $(OutDir) 目录中。因此,脚本必须知道 AdditionalLibraryDirectoriesAdditionalDependencies 的列表才能执行复制过程。

有人知道如何在 post-build-Event 脚本中访问它们吗?

像这样的东西应该是一个开始,将它添加到项目文件中 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets"/> 行之后的某处:

<Target Name="GetFullLibPaths" AfterTargets="Build">
  <ItemGroup>
    <Libs Include="%(Link.AdditionalDependencies)"/>
    <LibDirs Include="%(Link.AdditionalLibraryDirectories)"/>
    <!-- Combine them, 'cross product' -->
    <LibsAndDirs Include="@(Libs)">
      <Dir>%(LibDirs.Identity)</Dir>
    </LibsAndDirs>
    <!-- Filter on those which actually exist -->
    <LibPaths Include="@(LibsAndDirs)" Condition="Exists('%(LibsAndDirs.Dir)%(LibsAndDirs.Identity)')">
      <FullLibPath>%(Dir)\%(Identity)</FullLibPath>
    </LibPaths>
  </ItemGroup>

  <Message Text="MatchingLibs = %(LibPaths.FullLibPath)" />
</Target>

它将在构建后自动运行,列出库和目录,并查找有效存在于库目录中的库(跳过标准user32.lib等)。

然后您可以将这些 dll 复制到 OutDir,假设 dll 也在库目录中:

<Copy SourceFiles="%(LibPaths.Dir)\%(LibPaths.Filename).dll" DestinationFiles="$(OutDir)"/>