dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.17k stars 1.34k forks source link

Property function evaluation for global properties #8472

Open stan-sz opened 1 year ago

stan-sz commented 1 year ago

Per https://github.com/dotnet/msbuild/issues/7357#issuecomment-1344403099 can MSBuild have an opt-in mechanism to evaluate property functions passed both as command line args or through .rsp file? Possibly the opt-in mechanism could be through https://github.com/dotnet/msbuild/blob/07bf358dd7fa5037747a040f5e792d9dd82129aa/documentation/wiki/MSBuild-Tips-%26-Tricks.md#environment-variables (similar to the flag for allowing all property functions be used) or through a dedicated /evaluateGlobalPropertyFunctions

KalleOlaviNiemitalo commented 1 year ago

If new options -evaluateProperty:name=value and -evaluateRestoreProperty:name=value were added, then it would be possible to request evaluation separately for each property.

The MSBuild task that can be executed from targets does not need any changes here, I think.

AR-May commented 11 months ago

Team triage: Could you please give us an example of how you would use this and an expected output?

stan-sz commented 10 months ago

Example: -evaluateProperty:BuildStartTime="$([System.DateTime]::Now.ToString('yyyyMMdd-HHmmss'))" could resolve the property to a datetime string.

AR-May commented 10 months ago

Team triage: let's collect interest in this feature. fyi @baronfel

baronfel commented 10 months ago

Folks that use the containers tooling have demonstrated a similar use case. In their CI/CD script's they'll generate an unique tag for the image by using some other program (for example the date command available in most unix systems) and then they'll use the value of that as part of a -property:ContainerImageTag={{ env.DATE }} kind of variable interpolation inside of GitHub actions.

This is attractive to me for that reason, but I agree with collecting more user use cases.