28

I want to copy my dll generated in bin folder to a file location on Post Build Event in vs2010.

Can some one help me on that.

Thanks

Cody Gray
  • 230,875
  • 49
  • 477
  • 553
Praneeth
  • 2,497
  • 5
  • 30
  • 47

4 Answers4

61

You want to add something like:

xcopy /Q /Y "$(TargetPath)" "C:\path\to\somewhere\"

to you post-build event on the Build Events tab in the project properties page. The /Y will stop it from prompting you to confirm an overwrite.

If you also need to copy the .pdb file, you will need something like this:

xcopy /Q /Y "$(TargetDir)$(TargetName).*" "C:\path\to\somewhere\"

You can see more substitution tokens (the $XXX values) by clicking the Edit Post-build... button in the properties tab and then expanding the Macros>> button.

adrianbanks
  • 79,167
  • 22
  • 173
  • 203
  • 3
    Please tell me the diff between xcopy and copy. Why do we need to do /Q /Y here – Praneeth Jan 12 '11 at 01:10
  • 5
    `xcopy` is a more powerful version of `copy` with more options, and hence more control over how things are copied. It is also capable of copying directories. The `/Q` stops the names of the copied files from being written to the output window, and the `/Y` stops it prompting you if it needs to overwrite a file. – adrianbanks Jan 12 '11 at 01:18
4

Right-click the project, then go to Properties->Build Events->Post-build command line.

Then type this in:

Cmd /C Copy "$(TargetPath)" "<YourTargetDirHere>"

Does that help?

user541686
  • 197,378
  • 118
  • 507
  • 856
3

We use the following post build event for copying plugin dlls to the web application's plugin directory:

copy $(TargetPath) $(SolutionDir)Convergence.WebApp\home\plugins\$(TargetFileName)

This works across multiple machines where the physical path may be different, but relies upon the destination being relative to the $(SolutionDir).

Michael Shimmins
  • 19,721
  • 7
  • 55
  • 90
2

For those of you that want to copy everything from the Output folder

xcopy "$(TargetDir)*" "C:\testpublish\updater\"  /s /Y
Mihail Shishkov
  • 11,469
  • 6
  • 44
  • 56