none
Creating command line arguments for external program

    Question

  • Hi all,
      I'm trying to use Google Closure to compress our javascript files as part of our build process.  I'm having a bit of trouble with constructing the command line arguments.  They need to be of the following format

    java -jar Tools/GoogleCC/compiler -jar --js Scripts/file1.js --js Scripts/file2.js --js Scripts/file3.js --js Scripts/file4.js <etc etc> --js_output_file Scripts/Compresses/SiteFiles.js

    I've defined the following item groups in my build config.

      <ItemGroup>
                <FrameworkScripts Include="UserSite\Content\Scripts\**\*.js" Exclude="UserSite\**\MapScripts\**; UserSite\**\STMap2\**;UserSite\**\UnitTests\**" />
                <MapScripts Include="UserSite\Content\Scripts\MapScripts\**\*.js; UserSite\Content\Scripts\STMap2\**\*.js" />
            </ItemGroup>
    
            <Message Text="FrameworkScripts is @(FrameworkScripts)"/>
            <Message Text=" "/>
            <Message Text="MapScripts is @(MapScripts)"/>
    When I print out my item groups, they're perfect.  How can I construct the command line to pass to the exec target with the item groups I have?  If I manually edit the command everything works perfectly, I just can't get my item groups out in the correctly formatted string to execute the program.

    Thanks,
    Todd

    Wednesday, February 24, 2010 3:12 AM

All replies

  • You need to instruct MSBuild to use a different separator between the items. By default, i.e. with the statement @(ItemName), it just uses a semicolon. Instead of that use the following syntax: @(ItemName, 'separator'). The following example hopefully illustrates that:

      <ItemGroup>
        <Files Include="D:\Files\**\*"/>
      </ItemGroup>
    
      <Target Name="DemoTarget">
        <!-- Default -->
        <Message Text="@(Files)"/>
        <!-- Custom separator: '" --js "' -->
        <Message Text="--js &quot;@(Files, '&quot; --js &quot;')&quot;"/>
      </Target>
    

    This will print to strings. The first one is:
    D:\Files\file1.js;D:\Files\file2.js;D:\Files\file3.js;D:\Files\file4.js

    the second one is
    --js "D:\Files\file1.js" --js "D:\Files\file2.js" --js "D:\Files\file3.js" --js "D:\Files\file4.js"

    Note that before the item is addressed I place a "--js" and a quote infront of it. The separator between the files is first a quote followed by your command line argument followed by another quote for the next file.

    Now you just have to place "java -jar Tools/GoogleCC/compiler -jar " infront of that string and use it as input for the Exec task and it should work

    Hope that helps

    Wednesday, February 24, 2010 2:01 PM
  • Hi Todd,

    Have you followed ACKH's suggestion? Does it work for you? Thanks.

    Hongye Sun [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    See what's happening in MSDN forum? Follow us at Twitter.
    Monday, March 1, 2010 4:52 AM
    Moderator