29

I have the following in a prebuild event:

copy /y $(ProjectDir)ThirdPartyAssemblies\ $(TargetDir)

Which results in the following error:

The command "copy /y C:\Users\myusername\Documents\Visual Studio 2010\Projects\mysolution\myproject\ThirdPartyAssemblies* C:\Users\myusername\Documents\Visual Studio 2010\Projects\mysolution\myproject\bin\Debug\" exited with code 1.

I've tried it in a post build event too and get the same error. Yet when I run the command it results in (the one in the error) in a console window it works fine. What am I doing wrong?

Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
Mark Bostleman
  • 2,185
  • 3
  • 25
  • 32

5 Answers5

39

I'm not sure if it's related to the error you're receiving, but you need to place quotes around your path/file names since there are spaces in them.

copy /y "C:\Users\myusername\Documents\Visual Studio 2010\Projects\mysolution\myproject\ThirdPartyAssemblies*" "C:\Users\myusername\Documents\Visual Studio 2010\Projects\mysolution\myproject\bin\Debug\"

Michael Bowersox
  • 1,471
  • 11
  • 17
  • That was it, thanks - of course, I put the quotes in when I tested in the console, but it didn't occur to me that VS would need them too. – Mark Bostleman Apr 08 '12 at 13:53
15

copy /y "$(SolutionDir)MyProject\myFile.xxx" "$(TargetDir)" did not work for me. I pulled my hair out for 45 minutes until I stumbled across this page and then tried:

xcopy /y "$(SolutionDir)MyProject\myFile.xxx" "$(TargetDir)" 
Colin Pear
  • 3,028
  • 1
  • 29
  • 33
5

Also, you can do it by macros. In Post/Pre Build Event Command Line, expand macros.

copy  "$(TargetPath)" "$(SolutionDir)MyProject\Bin\Debug\";
Mazdak Shojaie
  • 1,620
  • 1
  • 25
  • 32
0

Check the path you have written inside command prompt, it can not found file or folder.

-2

In my case I changed the solution configuration from release to debug on each project and it solved the problem.

user1058637
  • 151
  • 1
  • 5