13

EDIT: This is a VS2008 app written in C#.

So I have a folder in my solution called

_lib/ 

It's where I keep my DLLs so that when I reference them, they get built into the bin/ folder.

Now I have a new item in my solution. It's a DLL but shouldn't be reference (it's required for a 3rd party app). So on build I want this to be copied from _lib/ to bin/ but NOT referenced in the project.

I've included the _lib/ folder in my app, and for the properties of that DLL I selected always copy. This ALMOST worked, it copies the file with the folder, so my structure looks like:

/bin/_lib/thedll.dll

Instead of

/bin/thedll.dll

Any ideas?

Grant Thomas
  • 44,454
  • 10
  • 85
  • 129
Ev.
  • 7,109
  • 14
  • 53
  • 87

1 Answers1

29

Try following these steps in Visual Studio:

  • Expand the project tree concerned

  • Double click the Properties element

  • In the opened window click the Build Events tab

  • In the Post-build event command line text area place this:

    xcopy "$(ProjectDir)_lib\file.ext" "$(ProjectDir)bin\$(ConfigurationName)"
    
  • Open the expected output folder alongside Visual Studio

  • Hit CTRL+Shift+B to make sure everything is saved and build

  • Feel the sense of achievement well up inside you as your file appears

  • :)

Oh, and you can now set Copy to output directory to Do not copy.

Grant Thomas
  • 44,454
  • 10
  • 85
  • 129
  • Disappointment: Ahhh my sense of achievement has never been so high! Heh heh :) Thanks for the answer, and it did indeed work. I actually considered doing it as a post build task, but thought "surely there's a setting I can use to just copy it directly" but alas, there's not. Thanks for the confirmation and detailed answer :) – Ev. Feb 15 '11 at 02:51
  • 2
    Just making a small edit - added /Y so it overwrites existing files in the output directory. Without this it causes an error after the first build. – Ev. Feb 15 '11 at 03:41