在 Post Build 事件 Visual Studio/MS Build 之后

After PostBuild event Visual Studio/MS Build

我在我的 C# 控制台项目 (Visual Studio 2017) 中使用外部库 UnmanagedExports。我的项目的 csproj 文件包含以下几行:

<DllExportLibToolPath>C:\Program Files (x86)\Microsoft Visual Studio17\Community\VC\Tools\MSVC.16.27023\bin\Hostx64\x64</DllExportLibToolPath>
<NoDllExportsForAnyCpu>false</NoDllExportsForAnyCpu>

在这些行和外部库的帮助下,我的构建过程首先生成了两个文件夹,x86 和 x64。之后,项目的 Post Build 事件将文件夹复制到另一个位置。

问题:

在 changing/updating 库之后,构建过程顺序发生了变化。现在,执行 Post 构建事件(复制),然后创建两个文件夹。当然,那是不行的。

有没有办法在项目构建完成后复制文件夹?不幸的是,post 构建事件 运行 太早了。

The post build event is unfortunately running too soon.

我们可以使用AfterTargets来控制构建顺序。

通常这样的事情会在构建完成后执行:

  <Target Name="CustomTarget" AfterTargets="build">
    <Exec Command="xxx"/>
    <!--copy the content from post-build event here-->
  </Target>

此目标甚至会在 post-build 目标之后执行。

在某些情况下,如果效果不佳,我们可以在 运行 之后检查我们想要的目标,然后使用 AfterTargets="TargetWhoCreateFolders" 之类的东西来设置构建顺序。