0

I want to copy a set of files from my project folder to the output folder using the post-build event. If the folder Settings does not exist, want to create it. I have tried the below code.

SET path=$(TargetDir)Config\Settings
if not exist "%path%" mkdir "%path%"
xcopy "$(SolutionDir)\Application\Resources" "$(TargetDir)Config\Settings"

The above code gives an error

The command "SET path=C:\Users\User1\Documents\Repo\bin\Config\Settings
if not exist "%path%" mkdir "%path%"
xcopy "C:\Users\User1\Documents\Repo\Sample\Application\Resources" 
"C:\Users\User1\Documents\Repo\bin\Config\Settings"" exited with code 9009.

If I remove the third line, the other two commands will be executed and the folder will be created. If I remove the first two lines and keep the third line, the command will be executed and files will be copied. But together three lines cause the error. Can someone help me to resolve this error? Do I need to create a batch file for this? I am using VS 2017. Thanks in advance

Edit: Error resolved

By giving the absolute path of xcopy.exe, issue resolved.

spc
  • 131
  • 5
  • 19
  • Look in the Output window for the command output, you'll see the error message that tells you why the command(s) failed. Surely it says "xcopy is not recognized....". Setting the path like that prevents the OS from finding xcopy.exe. Use SET path=%path%;$(TargetDir)Config\Settings or run c:\windows\system32\xcopy.exe – Hans Passant Apr 06 '23 at 09:18
  • It would help if you explained exactly how you execute these commands. I suspect you have typed that text in the "Post-build step" text box in project properties, but it is not clear. – Mike Nakis Apr 06 '23 at 09:19
  • @MikeNakis Yes I have typed like that – spc Apr 06 '23 at 10:44
  • @HansPassant Tried. It is not working – spc Apr 06 '23 at 11:12
  • Why on earth would you say "it is not working" when I explained how you can see the error message??? What does it say? Did you google the error message? – Hans Passant Apr 06 '23 at 11:16
  • @HansPassant Then why you commented 'Use SET path=%path%;$(TargetDir)Config\Settings or run c:\windows\system32\xcopy.exe' ? I thought changing SET or running the xcopy.exe will resolve the error. – spc Apr 06 '23 at 13:04
  • Does this answer your question? [What does "exited with code 9009" mean during this build?](https://stackoverflow.com/questions/1351830/what-does-exited-with-code-9009-mean-during-this-build) – phuzi Apr 06 '23 at 14:29

1 Answers1

-1

Your msbuild code can be simplified to:

xcopy /y $(SolutionDir)Application\Resources $(TargetDir)Config\Settings\

/y means overwrite if present

xcopy will automatically create the target folder for you

enter image description here

Jiale Xue - MSFT
  • 3,560
  • 1
  • 6
  • 21