Share via


Post build command to copy files

Question

Friday, March 9, 2018 4:08 PM

Dear all,

I need to copy files from my OuputDir folder whrre my binary gets copied into an other folder on my C: drive

For that I have enter the follwing command in my project Post build event :

XCOPY "$(OutDir)" "C:\Dev\Deploy\ /S /Y

I get an error with Exit code 4 -  nothing else

Any idea what is wrong ? If I execute that command from command prompt console it works

regards

All replies (9)

Monday, March 12, 2018 3:38 AM âś…Answered

Hi wakefun, 

I got the same error Exit code 4 as you with your post build event, when you switch to Output window, you could notice that the detailed error log(Make your MSBuild log to Detailed, Tools->Options->Projects and Solutions->Build and Run, set MSBuild project build output verbosity to Detailed). Following is the error in my side:

The error log shows it Invalid path for "bin\Debug". Actually, this is not a complete path. 

So, first, we should give a complete path, you could use the variable $(TargetDir), the path is:

C:\Users\<Username>\documents\visual studio 2015\Projects\TestSample\TestSample\bin\Debug\

However, this is not enough. We will still got the Exit code 4 error, because the  copy source should be files not folder, so we should make the copy source be files, just like Pavel A said, using wildcard *.

source: Copy task: https://msdn.microsoft.com/en-us/library/3e54c37h.aspx?f=255&MSPPError=-2147217396

So, the post build event should be:

XCOPY "$(TargetDir)*" "C:\Dev\Deploy\" /S /Y

Test it, and it works fine on my side. You can check if it works for you, if not, please let me know for free.

MSDN Community Support Please remember to click Mark as Answer. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].


Saturday, March 10, 2018 12:37 AM

Hi,

What is your platform? (Windows 10, 8.1, 7...)
What is your language? (it doesn't seem to be a line in batch file)

Regards,

Ashidacchi >> http://hokusosha.com/


Saturday, March 10, 2018 12:50 AM

Check this:

   XCOPY "$(OutDir)*.*" "C:\Dev\Deploy\ /S /Y


Saturday, March 10, 2018 1:04 AM

> What is your language? (it doesn't seem to be a line in batch file)

Sure, it does. XCOPY is a classical dos utility.

The command line, however, looks suspicious. "$(OutDir)" is a directory. The OP probably wants "$(OutDir)\" or only the exe file.

-- pa


Saturday, March 10, 2018 1:17 AM

@Pavel A,
  Thank you. I know XCOPY, since I used it in 1990'.
   Why I asked OP's platform? It was because quotations were not necessary in Windows 10.
Regards, 

Ashidacchi >> http://hokusosha.com/


Saturday, March 10, 2018 1:22 AM

Hi wakefun,

I guess drive letter would be needed in source description, if current directory is not specified or this batch file is in @(OutDir) folder.
e.g XCOPY "C:\$(OutDir)" "C:\Dev\Deploy\ /S /Y 

Regards,

Ashidacchi >> http://hokusosha.com/


Sunday, March 11, 2018 4:49 PM

Dear all,

Thnaks you for your all response. I will give it a try.

By the way my goal in this all process is that I need to copy the build to a Deploy folder in order to run a specificq tool command which is protecting and abfusicate the EXE file as the app works with a dongle.

regards


Monday, March 12, 2018 8:14 AM

Hi Leo, you suggestion works fine . Thanks a lot
Last issue I have now is that I need to run a setup package command in post build which is actually as bellow :

"C:\Program Files (x86)\Inno Script Studio\ISStudio.exe" -compile "app.iss"

Seems that it cannot execute this and no error in detail.

Any idea ?


Monday, March 12, 2018 9:59 AM

@wakefun, you are always welcome. Since this issue is different from the previous question, one thread one question is recommend. If above answer resolved your previous question, you can mark it as answer, this can be beneficial to other community members reading this thread and we could close this thread. I suggest you can open a new thread with some more info about latter issue, for example, the build log in the output, where is your app.iss?. I will track that question and I will try my best to give you a solution.

Thanks for your understanding and cooperation.

MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].