-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add property function GetStableHash for String #4986
Comments
Would authors using this hash code be happy with |
That's true. I don't like how GetHashCode works now, but it's also good to avoid unexpected changes. If we were to add a System.String.HashCode that generates a stable hash in addition to System.String.GetHashCode, that would resolve the problem. On the other hand, the warning I pasted previously explicitly says not to use them outside the application domain or persist them, so this might not be a problem. Also, if hashes are expected to "differ across .NET implementations," this just seems like more of the same. |
This method hashes a string without taking target framework or bitness into account. Fixes dotnet#4986
Add StableStringHash method This method hashes a string without taking target framework or bitness into account. Fixes dotnet#4986 Test StableStringHash
Some projects wish to include hashes of strings (often paths) in output folder names, which must be defined at evaluation time.
System.String.GetHashCode
is available but unsuitable for many desirable purposes: it's documented to vary across 64- and 32-bit .NET implementations and can also vary between .NET Framework and .NET Core.MSBuild has an internal method to get a stable hash that's currently used for IPC
https://github.com/microsoft/msbuild/blob/fa773bb8d44a358963481c02e772509dc408a6d9/src/Shared/CommunicationsUtilities.cs#L673-L707
We should expose it as
$([MSBuild]::StableStringHash())
.Open questions:
String.GetHashCode()
?The text was updated successfully, but these errors were encountered: