dotnet/msbuild

Support line continuation characters on Unix

Open

#585 建立於 2016年4月20日

在 GitHub 查看
 (5 留言) (0 反應) (0 負責人)C# (1,364 fork)batch import
Area: Enginehelp wantedneeds-designtriagedxplat

倉庫指標

Star
 (5,062 star)
PR 合併指標
 (平均合併 11天 7小時) (30 天內合併 125 個 PR)

描述

In some recent work I've had need to execute an external program, so the <Exec/> task comes in handy:

<Exec Command="configure" />

The problem, though, is that the command I really need to execute is long -- resulting in a line which is nearly 596 characters long:

<Exec
       Command="configure LD=&quote;...&quote; ... # plus hundreds more characters..."
/>

I want shorter lines, both to make it easier to read, and to simplify version control review and validation (long lines make for terrible diffs).

There are (at least?) two ways to make for shorter lines:

  1. Use more variables

    <PropertyGroup>
      <Ld>LD=&quot;@(Runtimes->'%(Ld)')&quot;</Ld>
      <!-- ... -->
    </PropertyGroup>
    <Exec
        Command="configure $(Ld) ..."
    />
    
  2. Use line continuations:

    <Exec
        Command="configure ^
          LD=&quot;...&quot; ^
          ..."
    />
    

Truth be told, I tried (1) first, but that doesn't work with xbuild on OS X (doh!).

So I try the Unix variant on (2):

<Exec
    Command="configure \
      LD=&quot;...&quot; \
      ..."
/>

...which promptly fails because \ is replaced with / at all instances in both xbuild and msbuild (which is why I'm bringing it up here... ;-).

What would be useful is some way of using line-continuation characters in a portable fashion. I can think of two ways to support this:

  1. On Unix, replace ^<newline> with \<newline>. This would allow us to use the Windows line-continuation character of ^ in a portable fashion.

    The problem with this is if there are any shells or commands for which a trailing ^ is appropriate, though I can't think of any programs which use ^ in this manner offhand.

  2. Fix the s#\#/#g replacement that MSBuild performs so that \<newline> can be used within the //Exec/@Command attribute. Then, we could use Conditional to have one command for Windows and a different command for Unix:

    <Exec
        Condition="' $(OS' == 'Windows_NT' "
        Command="this is a ^
          very long command"
    />
    <Exec
        Condition="' $(OS' != 'Windows_NT' "
        Command="this is a \
          very long command"
    />
    

貢獻者指南