Alen Lee
Alen Lee

Reputation: 2509

MSBuild error: The command exited with code 255

I want to do something before build, so I add the command line at the Pre-Build Event.

for /f "tokens=*" %a in ('dir /b /s /a-d "$(ProjectDir)lib"') do @copy "%a" "$(TargetDir)" /y

This command for the purpose to copy all the files in lib(project directory) to debug target.

But when I build the project, it has an error MSB3073: The command "for /f "tokens=*" %a in ('dir /b /s /a-d "$(ProjectDir)lib"') do @copy "%a" "$(TargetDir)" /y :VCEnd" exited with code 255. But I execute the command in CMD, there is no problem.

Anyone know, How to resolve this issue? The IDE is VS2013, C++ project

Does the for may just not work in a batch file for visual studio?

Upvotes: 4

Views: 19211

Answers (1)

uncletall
uncletall

Reputation: 6842

There is a difference when running commands in a batch script. You need to double your % signs. Try this:

for /f "tokens=*" %%a in ('dir /b /s /a-d "$(ProjectDir)lib"') do @copy "%%a" "$(TargetDir)" /y

Upvotes: 10

Related Questions