.net - 构建后的 MsBuild 复制文件

我想在构建项目后将一个 xml 文件从主目录复制到 bin\Debug,但我的解决方案不起作用。我编辑了 .csproj 文件并添加了:

<Target Name="AfterBuild">
     <Copy SourceFiles="Controllers.xml" DestinationFolder="\bin\Debug" ContinueOnError="true" />
</Target>

我做错了什么?构建成功。

最佳答案

您的目标文件夹(很可能)错误。如果使用前导反斜杠指定它,它实际上只是 <current-drive-letter>\bin\Debug 的简写形式。 (使其有效地成为绝对路径,例如 C:\bin\Debug )。

使用bin\Debug ,或者更好的是使用 OutputPath变量,设置为 bin\Debugbin\Release取决于您的构建配置。

例子:

<Target Name="AfterBuild">
     <Copy SourceFiles="Controllers.xml" DestinationFolder="$(OutputPath)" ContinueOnError="true" />
</Target>

https://stackoverflow.com/questions/12384628/

相关文章:

recursion - 如何在 NuSpec 文件中递归地包含目录

.net - 有没有办法在 NAnt 中动态加载属性文件?

ios - 在命令行中清理 IOS xcode 目标

c++ - 包括 .cpp 而不是 header(.h)

visual-studio - TFS 构建损坏 - 源目录上的目录不为空

java - 使用 Gradle 的 Application 插件添加类路径条目

c - "make clean"结果 "No rule to make target ` 干净 '"

gradle - 为什么我收到 "could not find com.android.tools.

c++ - 在构建我的 C++ 可执行文件 (gcc) 时,我可以获得所有链接库的报告吗? (包括静

android - targetSdkVersion 和项目构建目标之间的区别