MSBuild error: The command exited with code 255

13,996

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
Share:
13,996
Alen Lee
Author by

Alen Lee

Updated on June 09, 2022

Comments

  • Alen Lee
    Alen Lee almost 2 years

    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?