简体   繁体   English

生成后的MsBuild复制文件

[英]MsBuild copy file after build

I want to copy an xml file from the main directory to bin\\Debug after building the project, but my solution doesn't work. 我要在构建项目后将xml文件从主目录复制到bin\\Debug ,但是我的解决方案不起作用。 I edited .csproj file and added: 我编辑了.csproj文件并添加了:

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

What am I doing wrong? 我究竟做错了什么? The build is successful. 构建成功。

Your destination folder is (most likely) wrong. 您的目标文件夹(很可能)是错误的。 If you specify it with a leading backslash, it is actually just a shortform for <current-drive-letter>\\bin\\Debug (making it effectively an absolute path, like C:\\bin\\Debug ). 如果以反斜杠开头,则实际上只是<current-drive-letter>\\bin\\Debug (有效地使其成为绝对路径,例如C:\\bin\\Debug )。

Either use bin\\Debug , or better yet use the OutputPath variable, which is set to either bin\\Debug or bin\\Release depending on your build configuration. 请使用bin\\Debug ,或者最好使用OutputPath变量,该变量根据您的构建配置设置为bin\\Debugbin\\Release

Example: 例:

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

Is the xml file in your project? xml文件在您的项目中吗? Then one of its properties is CopyToOutputDirectory. 然后,它的属性之一是CopyToOutputDirectory。 Set it to CopyAlways and when the project builds the file will be copied out to bin\\debug. 将其设置为CopyAlways,然后在构建项目时将文件复制到bin \\ debug。

You have to specify the full path. 您必须指定完整路径。 I suspect the MsBuild copy task is running from the "Default path" of Visual Studio, and the file can not be found. 我怀疑MsBuild复制任务是从Visual Studio的“默认路径”运行的,找不到该文件。 Also, you most likely want the file to end up in the build target directory. 同样,您很可能希望文件最终位于构建目标目录中。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM