Oddleif
Oddleif

Reputation: 801

MSBuild exec task with for

I am trying to run the following commands as part of an MSBuild script:

for /R . %f in (*.targets) do copy /Y "%f" "C:\Program Files (x86)\MSBuild\Microso
ft\VisualStudio\TeamBuild"

The commands is implemented in an exec the following way:

<Exec WorkingDirectory="$(SolutionRoot)" Command="for /R . %f in (*.targets) do copy /Y &quot;%f&quot; &quot;$(MSBuildExtensionsPath)\Microsoft\VisualStudio\TeamBuild&quot;" />

The command works fine from console, but when trying to run it from MSBuild I get the error:

Task "Exec"
  Command:
  for /R . %f in (*.targets) do copy /Y "%f" "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\TeamBuild"
  f" "C:\Program was unexpected at this time.
C:\Users\rd-build\AppData\Local\Temp\OH Test2\Continuous.BuildTargets\BuildType\TFSBuild.proj(98,5): error MSB3073: The command "for /R . %f in (*.targets) do copy /Y "%f" "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\TeamBuild"" exited with code 255.
Done executing task "Exec" -- FAILED.

Any suggestions?

Upvotes: 1

Views: 5345

Answers (2)

kokeksibir
kokeksibir

Reputation: 1765

I have just explained in your previous question. In that case you need to add extra % in front of your variables. It is explained in help of FOR command as follows

To use the FOR command in a batch program, specify %%variable instead of %variable.

Upvotes: 5

Oddleif
Oddleif

Reputation: 801

Had to use %% and not %.

Upvotes: 0

Related Questions