dotnet / docs

This repository contains .NET Documentation.
https://learn.microsoft.com/dotnet
Creative Commons Attribution 4.0 International
4.21k stars 5.87k forks source link

New feature: Throwaway (out) parameters in MSBuild property functions #41828

Open Forgind opened 1 month ago

Forgind commented 1 month ago

Describe the issue or suggestion

With https://github.com/dotnet/msbuild/pull/10209, we now permit users to use functions with out parameters and ref parameters as long as they don't care about the values that come out of them. Specifically, if a parameter is specified by '', it will look for any method with the right name from the right assembly and try to match based on number of parameters. If there are multiple options, it will throw; if there is only one, it will execute it after tweaking all the to have the right type.

Example: $([System.Int32]::TryParse("3", _))

Limitation: This tries to infer which method overload of TryParse (or other function) to use, but if there are multiple overloads that could equally well fit the provided parameters and underscores, this will fail to determine definitively which function to use and will throw an error instead. This includes if a method currently has no conflicting overloads, and a new overload is added, which means a customer may see a breaking change in updating the version of an assembly in which the version update adds a new overload for a method they invoke that is indistinguishable from the method they intend to use. (I think this is very unlikely to occur, but it theoretically could.)

JanKrivanek commented 1 month ago

The request is for changing this article: https://learn.microsoft.com/en-us/visualstudio/msbuild/property-functions?view=vs-2022#calling-instance-methods-on-static-properties

rainersigwald commented 1 month ago

Please hold on this, I'm backing out the MSBuild change.