Reputation: 5230
Basically I have a command which will copy the contents of a source directory (and sub-directories), and flatten the structure into a target directory, overwriting any duplicates.
This is the raw command that works from the command line
for /r 5.1.0.60 %f in (*) do @copy "%f" "deployment" /y
in this instance where
However, when I run this command from inside of an MSBuild task (ultimately as part of a TeamCity build), I am getting the following error
f" deployment /y was unexpected at this time
I have the following basic msbuild script that exhibits the issue:
<Project DefaultTargets="flatten"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
ToolsVersion="3.5">
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
<PropertyGroup>
<SourceDir>5.1.0.60</SourceDir>
<TargetDir>deployment</TargetDir>
</PropertyGroup>
<Target Name="flatten">
<!-- create our deployment directory -->
<MakeDir Directories="$(TargetDir)"/>
<!-- Copy all files flattenend to the deployment directory-->
<Message Text="##Command [for /r $(SourceDir) %f in (*) do @copy "%f" $(TargetDir) /y]"/>
<Exec Command="for /r $(SourceDir) %f in (*) do @copy "%f" $(TargetDir) /y" />
</Target>
</Project>
Ultimately, if a past the line
for /r 5.1.0.60 %f in (*) do @copy "%f" "deployment" /y
into a batch file and run the batch file on its own (outside of msbuild) I get the same error, so presumably it's strictly a cmd issue rather than MSBuild, though since I imagine this is a common task in MSBuild / TeamCity I've tagged those as well.
Any help or pointers would be most appreciated. (NB windows 7 pro, TeamCity 6.5)
Upvotes: 2
Views: 2815
Reputation: 130919
FOR variables use a single percent (%f) when used on the command line, but two percents (%%f) are required when used in in a batch file.
I'm not sure if TeamCity executes your command in a command line context or from within a temporary batch file.
Upvotes: 5