Msbuild exec和curl:引用噩梦

Hen*_*rik 3 msbuild curl cmd

以下msbuild Exec语句

<Exec Command="curl.exe -f -O --url &quot;$(SourceURL)&quot;">
Run Code Online (Sandbox Code Playgroud)

如果SourceURL包含空格,则失败。即使我尝试

<PropertyGroup>
    <SourceURL>http://www.example.com/url%20with%20spaces</SourceURL>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)

甚至

<PropertyGroup>
    <SourceURL>http://www.example.com/url&37;20with&37;20spaces</SourceURL>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)

msbuild自动将其中的任何内容转换为空格(您相信吗?),然后curl尝试获取http://www.example.com/url,从而产生404错误。

我不懂为什么。我没有正确引用URL参数吗?

[ update ]在命令提示符下,以下工作:

curl.exe -f -O --url "http://www.example.com/url%20with%20spaces"
Run Code Online (Sandbox Code Playgroud)

虽然这不是:

curl.exe -f -O --url "http://www.example.com/url with spaces"
Run Code Online (Sandbox Code Playgroud)

因此,我的问题实际上可以归结为:如何防止msbuild被%20空白取代?

欢呼
亨德里克

curl 7.21.7 (i386-pc-win32) libcurl/7.21.7 OpenSSL/0.9.8r zlib/1.2.5在Windows 7上使用和msbuild 3.5.30729.1)

Hen*_*rik 5

问题是:

  1. MSBuild替换%20为空白
  2. 即使您使用%2520或来转义百分号&37;20,cmd.exe仍将替换%2为空字符串,以便在命令行上保留0。

因此解决方案是:

<PropertyGroup>
    <SourceURL>http://www.example.com/url%25%2520with%25%2520spaces</SourceURL>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)

啊啊 谁能从如此精心设计的逃生程序中摆脱头痛呢?