I have the following code in my MSBuild project file:
<Error Text="Some Text" Condition="'$(StringName)' != 'Test'"/>
The string comparison here is case-sensitive, so when $(StringName)
is something like 'test'
, the condition is not met.
How can I change the condition so that 'test'
also meets the comparison? Is there any case-insensitive comparison function available in MSBuild?
Comparing strings in a case insensitive manner means to compare them without taking care of the uppercase and lowercase letters. To perform this operation the most preferred method is to use either toUpperCase() or toLowerCase() function. Example 1: This example uses toUpperCase() function to compare two strings.
All environment variables are available to the MSBuild as properties. So we can simply access them in the same way we access properties i.e. by encapsulating their name in $(environmental_variable_name). Property names are not case sensitive, so PATH and Path would refer to the same property.
CompareTo and Compare(String, String) methods. They all perform a case-sensitive comparison.
Java String equalsIgnoreCase() Method The equalsIgnoreCase() method compares two strings, ignoring lower case and upper case differences. This method returns true if the strings are equal, and false if not. Tip: Use the compareToIgnoreCase() method to compare two strings lexicographically, ignoring case differences.
Dan Moseley has a detailed view on MSBuild Property Functions here:
http://blogs.msdn.com/b/visualstudio/archive/2010/04/02/msbuild-property-functions.aspx
For your example you could use something like:
<Error Text="Some Text" Condition="'$(StringName.ToUpper())' != 'TEST'"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With