Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you perform a case-insensitive string comparison in MSBuild?

Tags:

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?

like image 382
crauscher Avatar asked Oct 12 '09 12:10

crauscher


People also ask

How do you compare two string cases insensitive?

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.

Is MSBuild property case-sensitive?

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.

Are string comparisons case-sensitive?

CompareTo and Compare(String, String) methods. They all perform a case-sensitive comparison.

How do you make a string case-insensitive?

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.


1 Answers

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'"/>
like image 121
Sérgio Rocha Avatar answered Sep 21 '22 15:09

Sérgio Rocha