Bug #10121: Add possibility to control whether to fix the paths of TaskItem using metadata #10126
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bug #10121: Add possibility to control whether to fix the paths of TaskItem using metadata
To be able to have TaskItems that you don't want normalised, or you want then normalised to another OS, e.g. when using dotnet publish to containers to another OS than you are building on, I suggest using "magic" metadata names to be able to tell in an MSBuild file that you want a property on your build item of type TaskItem to either:
Fixes #10121
Context
When using dotnet to publish to containers, the EntryPoint and AppCommand are normalised on the build platform, not to the target platform, so if building a Windows container on Unix, the paths end up as C:/app/foo.exe instead of C:\app\foo.exe in the build Docker image. And, conversely on *nix.
Related to bug dotnet/sdk#559
Changes Made
Added the option to supply "magic"/special metadata items to TaskItem, to control how the paths are fixed (or not), when creating a TaskItem.
Added an overload of FileUtilities.FixFilePath that takes in a target OS that is used for the above mentioned functionality
Testing
Wrote unit tests on the TaskItems, both for current functionality (to be sure not to break anything), and wrote tests for new functionality
Notes
This is my first contribution to the MSBuild repository, so please tell me if I've done anything in another way that you prefer.