views:

50

answers:

3

Hi,

Q1 - When doing a compile/debug is VS suppose to delete existing files in the bin\debug area? (for VS2008)

if no then can I ask please:

Q2 - My winforms checks for existance of a sqlite.db3 file and creates it if it needs to (programmatically). If the behavior I wanted was that each Compile/Debug I do is for the target Debug area to be clear, so that the program would exercise the code that builds the database file, how would I organise this?

thanks

+2  A: 

Simply add a PreBuild event.

Edited to add:

Well... looks like someone wants it all chewed up and ready to swallow. Okie dokie!

  1. Right click the Project and select properties
  2. Navigate to

    a. Compile tab and click on the Build Events button if a VB project

    b. Build Events tab if it's a C# project

  3. in the pre-build event command line type:

    IF EXIST "$(TargetDir)\sqlite.db3" DEL "$(TargetDir)\sqlite.db3"

That should do it.

Next time, fiddle a little longer...

Paulo Santos
thanks - first time re build events - I'll try to find a reference page for the build event syntax
Greg
+1  A: 

There are events you can run before, after build for each project. So, pick the first/last project that builds depending on whether the action should happen before build or after build (enforce it by making it depend on every other project) and add some batch scripting to perform what you need. MSBuild tasks are great for this as well.

Hamish Grubijan
+2  A: 

"Clean" will only delete files that Visual Studio is explicitly copying to the target directory (your executable, dependent dlls, and those files marked with appropriate "Copy to Output Directory" values).

You might create a pre-build or post-build task to delete the file in question. Something like del $(TargetDir)\sqlite.db3. See the "Build Events" tab in your project properties for these events.

Michael Petrotta
thanks - getting a "the command...exited with code 1" - any ideas? The path looks fine, although there are spaces in it. Also is there a way to do a "If exists Then del xxx" in a pre-build task?
Greg
@Greg - yes, there is. See Paulo's answer.
Michael Petrotta