我正在尝试使用 MSBuild 社区任务删除 OutputPath 末尾的斜杠
这就是我到目前为止所拥有的。
<RegexReplace Input="$(OutputPath)" Expression="\$" Replacement="" Count="1">
<Output ItemName="FormattedOutputPath" TaskParameter="Output" />
</RegexReplace>
<Message Text="@(FormattedOutputPath)"/>
不幸的是,该消息仅返回我的路径,末尾仍带有斜杠。 路径是C:\MyDirectory\
看来我的表达不正确
有人可以帮忙吗?
最佳答案
斜杠用作转义字符,因此在模式中您必须用另一个斜杠转义斜杠字符:
<RegexReplace Input="$(OutputPath)" Expression="\\$" Replacement="" Count="1">
<Output ItemName="FormattedOutputPath" TaskParameter="Output" />
</RegexReplace>
<Message Text="@(FormattedOutputPath)"/>
为了更好地理解转义,请参阅以下示例:
$
表示行/字符串结束\$
表示美元符号字符\\
表示斜杠字符\\$
表示行/字符串末尾的斜杠字符
关于regex - MSBuild 社区任务 RegexReplace 从路径中删除尾部斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11247522/