Msbuild exec 和curl:引用噩梦
以下 msbuild Exec 语句
<Exec Command="curl.exe -f -O --url "$(SourceURL)"">
如果 SourceURL 包含空格,则 将失败。即使我尝试
<PropertyGroup>
<SourceURL>http://www.example.com/url%20with%20spaces</SourceURL>
</PropertyGroup>
甚至
<PropertyGroup>
<SourceURL>http://www.example.com/url&37;20with&37;20spaces</SourceURL>
</PropertyGroup>
msbuild 自动将其中任何一个转换为空格(你能相信吗?)并且curl 尝试获取http://www.example.com/url
,这会产生 404 错误。
我不明白为什么。我没有正确引用 URL 参数吗?
[更新] 在命令提示符下,以下内容有效:
curl.exe -f -O --url "http://www.example.com/url%20with%20spaces"
而这不起作用:
curl.exe -f -O --url "http://www.example.com/url with spaces"
所以我的问题实际上归结为:如何防止 msbuild 将 %20
替换为空白?
干杯
Hendrik
(在 Windows 7 上使用 curl 7.21.7 (i386-pc-win32) libcurl/7.21.7 OpenSSL/0.9.8r zlib/1.2.5
和 msbuild 3.5.30729.1)
the following msbuild Exec statement
<Exec Command="curl.exe -f -O --url "$(SourceURL)"">
fails if SourceURL contains spaces. Even if I try
<PropertyGroup>
<SourceURL>http://www.example.com/url%20with%20spaces</SourceURL>
</PropertyGroup>
or even
<PropertyGroup>
<SourceURL>http://www.example.com/url&37;20with&37;20spaces</SourceURL>
</PropertyGroup>
msbuild automagically translates any of this to spaces (can you believe that?) and curl tries to fetch http://www.example.com/url
, which yields a 404 error.
I do not understand why. Did I not properly quote the URL argument?
[update] On a command prompt, the following works:
curl.exe -f -O --url "http://www.example.com/url%20with%20spaces"
while this doesn't:
curl.exe -f -O --url "http://www.example.com/url with spaces"
So my question really boils down to: how do I prevent msbuild from replacing %20
with whitespace?
cheers
Hendrik
(Using curl 7.21.7 (i386-pc-win32) libcurl/7.21.7 OpenSSL/0.9.8r zlib/1.2.5
and msbuild 3.5.30729.1 on Windows 7)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是:
%20
替换为空格%2520
或&37;20
转义百分号,cmd .exe 会将%2
替换为空字符串,这样 0 就会保留在命令行上。所以解决办法是:
啊啊啊。如此精心设计的逃脱序列谁不感到头疼呢?
The problem is:
%20
with whitespace%2520
or&37;20
, cmd.exe will replace%2
with an empty string, such that a 0 remains on the command line.So the solution is:
Aaaargh. Anyone who doesn't get a headache from such an elaborate escape sequence?
您还需要转义
&
符号:You need to escape the
&
sign as well: