【问题标题】:Escaping a dollar sign in Postbuild在 Postbuild 中转义美元符号
【发布时间】:2019-05-21 16:05:08
【问题描述】:

我正在尝试在 Postbuild 中执行一个使用美元符号的命令。我已经尝试了所有解决方案here,但都没有工作。

echo "$(runtime.testbin)"

当我尝试构建时尝试这样做会引发异常,我尝试转义:

echo "%24(runtime.testbin)"

但这会打印出来:

1> "4(runtime.testbin)"

我也试过了:

echo "%2524(runtime.testbin)"

哪个打印:

1> "524(runtime.testbin)"

【问题讨论】:

    标签: visual-studio msbuild post-build


    【解决方案1】:

    您可能需要对美元符号和以下括号进行编码(不一定是右括号,但我个人认为仅对其中一个进行编码看起来很难看):

    <PropertyGroup>
      <PostBuildEvent>echo "%24%28hello%29"</PostBuildEvent>
    </PropertyGroup>
    

    【讨论】:

    • 啊,你是对的。使用编码保存 .csproj 后,它就像一个魅力!
    • 我不得不调用 MSBuild 的内部 Microsoft.Build.Evaluation.IntrinsicFunctions.Encode() 方法来了解如何正确编码..
    【解决方案2】:

    您的命令是否必须类似于:$(runtime.testbin)?

    在 msbuild 中,$(xxx) 格式将被识别为 Msbuild Property 的值。

    也许你可以试试:

    echo $ (runtime.testbin)=>$ (runtime.testbin)

    echo "$ (runtime.testbin)"=>"$ (runtime.testbin)"

    echo $ runtime.testbin=>$ runtime.testbin

    echo $:(runtime.testbin)=>$:(runtime.testbin)

    更新: 马丁的回答就像一个魅力!实际上简单的文件编码可以使echo "%24(runtime.testbin)"工作。

    【讨论】:

      猜你喜欢
      • 2015-06-17
      • 2021-07-01
      • 2022-11-22
      • 1970-01-01
      • 2017-02-19
      • 1970-01-01
      • 2021-04-25
      • 2013-05-28
      • 1970-01-01
      相关资源
      最近更新 更多