0

So I'm kind of new to the scripting and XMl but I'm trying to get my head arround it.

I'm working on a project where I have to replicate certain commands from scripts to XML using Tasks and Targets and then run it with a MSBuild in TFS 2015.

I have been having trouble trying to replicate one that "calls" an .exe file and gives another file as a parameter to convert it, then it outputs to a specific dir. We are using environment variables so it goes something like this:

"%CONVERTER_TOOL%" "%FILE_TO_CONVERT%" "OUTPUT_DIR"

this is how the command is written in the Generate.cmd file.

I did this on a .csproj, the variables listed are already set by a config file I call first when queing the MSBuild.

<ItemGroup>
    <Converter Include="$(CONVERTER_TOOL)"/>
</ItemGroup>
<ItemGroup>
    <FileToConvert Converte Include="$(FILE_TO_CONVERT)"/>
</ItemGroup>
<ItemGroup>
    <OutDir Include="$(OUTPUT_DIR)"/>
</ItemGroup>
<Target Name="">
    <Exec Command="@(Converter.Identity) @(FileToConvert.Identity)
    @(OutDir)"/>
 </Target>

But it keeps giving me this error and I can't solved it.

Error:

@(FileToConvert.Identity) was unexpected at this time.

I think I'm build the Command in the wrong way. :/

Anyone have any clue about this?

Thanks in advance. :)

Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39
1111 1100
  • 3
  • 2
  • hard to tell what you want exactly, but likely you need something like %(FileToConvert.Identity) or else just @(FileToConvert) – stijn Jul 28 '16 at 19:27

1 Answers1

0

If I understood you correctly you have single converter tool (referenced by environment variable) and single output directory. Then, you might have many files to convert. In your case you're trying to do batching over both converter and files, which is not what needed. Instead you need to use PropertyGroup for items with single value (like Converter):

<PropertyGroup>
    <Converter>$(CONVERTER_TOOL)</Converter>
    <OutDir>$(OUTPUT_DIR)</OutDir>
</PropertyGroup>
<ItemGroup>
     <FileToConvert Include="$(FILE_TO_CONVERT)"/>
</ItemGroup>
<Target Name="">
    <Exec Command="$(Converter) %(FileToConvert.Identity) $(OutDir)"/>
</Target>

This will call $(Converter) tool as many time as you have files in the FileToConvert item group.

If you want to call converter for all files at once (they'll be passed to command line split by space) use @(FileToConvert) in the Exec command.

If you know for sure that there is only single file to convert - don't use ItemGroup for it, use PropertyGroup as for Converter and OutDir.

Igor Labutin
  • 1,406
  • 10
  • 10