MSBuild Community Taks RegexReplace remove trailing slash from path
-
17-06-2021 - |
Pergunta
I am trying to use MSBuild community tasks to remove the slash from the end of the OutputPath
This is what i have so far.
<RegexReplace Input="$(OutputPath)" Expression="\$" Replacement="" Count="1">
<Output ItemName="FormattedOutputPath" TaskParameter="Output" />
</RegexReplace>
<Message Text="@(FormattedOutputPath)"/>
Unfortunately the message just returns my path still with the slash on the end. The path is C:\MyDirectory\
It looks like my expression is incorrect
Can anyone help?
Solução
Slash is using as an escape character, so in pattern you have to escape slash character by another slash:
<RegexReplace Input="$(OutputPath)" Expression="\\$" Replacement="" Count="1">
<Output ItemName="FormattedOutputPath" TaskParameter="Output" />
</RegexReplace>
<Message Text="@(FormattedOutputPath)"/>
To better understand escaping see the following examples:
$
represents end of line/string\$
represents dollar sign character\\
represents slash character\\$
represents slash character at the end of line/string
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow