views:

845

answers:

3

I've been desperately looking for the answer to this and I feel I'm missing something obvious.

I need to copy a folder full of data files into the TARGETDIR of my deployment project at compile time. I can see how I would add individual files (ie. right click in File System and go to Add->File) but I have a folder full of data files which constantly get added to. I'd prefer not to have to add the new files each time I compile.

I have tried using a PreBuildEvent to copy the files:

copy $(ProjectDir)..\Data*.* $(TargetDir)Data\

which fails with error code 1 when I build. I can't help but feel I'm missing the point here though. Any suggestions?

Thanks in advance.

Graeme

A: 

Try

xcopy $(ProjectDir)..\Data\*.* $(TargetDir)Data /e /c /i [/f] [/r] /y

/e to ensure tree structure fulfilment (use /s if you want to bypass empty folders)
/c to continue on error (let the build process finish)
/i necessary to create the destination folder if none exists
/y assume "yes" for overwrite in case of previously existing files

[optionnal]
/f if you wanna see the whole pathes resulting from the copy
/r if you want to overwrite even previously copied read-only files

The method is simpler on the project than on files, yes. Beside, on files, it copies only the modified/missing files on each build but forces you to maintain the project on each data pack modification. Depends on the whole data size and the variability of your data pack.

Also beware the remaining files if you remove some from your data pack and rebuild without emptying your target folder.

Good luck.

A: 

I solved the problem by a workaround:

  • Add a build action of packaging entire directory (could be filtered) to a ZIP file.
  • Add a reference to an empty ZIP file to deployment project.
  • Add a custom action to deployment project to extract the ZIP to destination folder.

It's simple and stable.

A: 

I'm trying to do the same thing. Can you elaborate on exactly how this method works.

I can see that you must write a macro to zip the files, and add it to the post build event.

But how do you get it to extract?

Do you have any code samples?

Urbycoz