Mehul Vaghela
Mehul Vaghela

Reputation: 478

Post Build event xcopy - exclude some set of files

I want to copy some of the files to the specific folder after the successful compilation of the project. I have written a post build event as mentioned below:

xcopy "$(ProjectDir)bin" "$(TargetDir)..\..\Support Files\DBUpgradeUtility\" /Y

Note: the output path of my project has been set to bin folder for debug and release both the mode.

The above mentioned build event worked fine and all the files present under bin folder has been copied to destination folder. But along with the required files, the ‘vshost.exe’ files also copied, I don’t’ want this file. So, I have used the exclude parameter of xcopy build event as mentioned below:

xcopy "$(ProjectDir)bin" "$(TargetDir)..\..\Support Files\DBUpgradeUtility\" /Y /exclude:$(TargetDir)..\..\Support Files\DBUpgradeUtility\*.vshost.exe

With the above build event, the compilation failed and the error was:

The command "xcopy "C:\TFSWorkspace\FASTER.Web - v6.3.Sprint.06\Source\Installer\Application\DBUpgradeUtility\bin" "C:\TFSWorkspace\FASTER.Web - v6.3.Sprint.06\Source\Installer\Application\DBUpgradeUtility\bin....\Support Files\DBUpgradeUtility\" /Y /exclude:"C:\TFSWorkspace\FASTER.Web - v6.3.Sprint.06\Source\Installer\Application\DBUpgradeUtility\bin....\Support Files\DBUpgradeUtility*. vshost.exe" exited with code 4.

I have also googled for exclude parameter and then written the build event mentioned above. I cannot find what I am missing here or what I did wrong.

Please help me on this.

Thank you.

Upvotes: 1

Views: 2136

Answers (1)

marapet
marapet

Reputation: 56526

The /exclude option of the xcopy command works differently - it allows you to specify files which contain exclude filters:

Specifies a list of files. At least one file must be specified. Each file will contain search strings with each string on a separate line in the file.

When any of the strings match any part of the absolute path of the file to be copied, that file will be excuded from being copied. For example, specifying the string, \obj\ or .obj will exclude all files underneath the directory obj or all files with the .obj extension.

Therefore you may create a new file in your project (for example $(ProjectDir)excludes.txt) and add this line:

vshost.exe

Then change the option in your xcopy command to:

/exclude:"$(ProjectDir)excludes.txt"

This excludes all files containing vshost.exe in their absolute path. If you have to exclude other files, just add a new line to the file.

Upvotes: 1

Related Questions