Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MsBuild copy file after build

Tags:

I want to copy an xml file from the main directory to bin\Debug after building the project, but my solution doesn't work. I edited .csproj file and added:

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

What am I doing wrong? The build is successful.

like image 470
KlimczakM Avatar asked Sep 12 '12 09:09

KlimczakM


1 Answers

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

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.

Example:

<Target Name="AfterBuild">      <Copy SourceFiles="Controllers.xml" DestinationFolder="$(OutputPath)" ContinueOnError="true" /> </Target> 
like image 89
Christian.K Avatar answered Oct 10 '22 08:10

Christian.K