为外部程序创建命令行参数 [英] Creating command line arguments for external program

查看:72
本文介绍了为外部程序创建命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
 我正在尝试使用Google Closure压缩javascript文件,这是我们构建过程的一部分.在构建命令行参数时遇到了一些麻烦.它们必须采用以下格式

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)"/>

当我打印出项目组时,它们是完美的.如何构造命令行以将具有的项目组传递给exec目标?如果手动编辑命令,一切将正常工作,那么我将无法以正确格式的字符串显示项目组来执行程序.

谢谢,
托德

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

推荐答案

您需要指示MSBuild在项目之间使用不同的分隔符.默认情况下,即使用语句@(ItemName),它仅使用分号.而不是使用以下语法:@(ItemName,'separator').以下示例有望说明这一点:

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>

这将打印为字符串.第一个是:
D:\ Files \ file1.js; D:\ Files \ file2.js; D:\ Files \ file3.js; D:\ Files \ file4.js

第二个是
--js"D:\ Files \ file1.js" --js"D:\ Files \ file2.js" --js"D:\ Files \ file3.js" --js"D:\ Files \ file4.js"

请注意,在解决该问题之前,我先放置了一个"--js"并在其前面加引号.文件之间的分隔符首先是一个引号,然后是您的命令行参数,然后是下一个文件的另一个引号.

现在,您只需要放置"java -jar Tools/GoogleCC/compiler -jar" "该字符串的开头,并将其用作Exec任务的输入,它应该可以运行

希望有帮助的

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


这篇关于为外部程序创建命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆