dotnet / dotnet/msbuild

[Bug]: TaskItem normalises path to build platform, not target platform

Open
#10,121 8 comments 1 reaction 0 assignees View on GitHub
Area: Language bug gathering-feedback triaged xplat
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

### Issue Description

I've been working a bit on a bug in the dotnet/sdk#559, and stumbled upon something that _might_ be considered a bug in either Microsoft.Build.Utilities.TaskItem, or Microsoft.Build.Shared.FileUtilities.FixFilePath. One might also argue that it's not a bug, and that it's the usage of it in Microsoft.NET.Build.Containers.Tasks.CreateNewImage that is wrong.

Anyway, the problem is, when publishing dotnet projects to containers, some properties are set on the [CreateNewImage](https://github.com/dotnet/sdk/blob/dd843a86ae8d907fd9c68a42c3dd5c8670d7f74b/src/Containers/Microsoft.NET.Build.Containers/Tasks/CreateNewImage.cs#L14) MSBuild task, that are needed runtime in the built container. So, the paths need to be compatible with the container target platform, not the platform it's built on. The properties in question are (at least) Entrypoint, EntrypointArgs, AppCommand, AppCommandArgs.

However, as the properties are of type `ITaskItem`, implemented by `TaskItem`, the paths are normalised when initialised. And, the normalisation uses the Path.DirectorySeparatorChar of the build platform, not the target.

Would you consider this a bug/shortcoming in the `TaskItem`, or are we/they using it in the wrong way in the MSBuild task?

### Steps to Reproduce

Use a `TaskItem` in an MSBuild task, where you need the directory separator char of a different platform than the one you are building on (e.g. use C:\app\foo.exe when building on *nix)

### Expected Behavior

The item should stay as C:\app\foo.exe

### Actual Behavior

The path is changed to C:/app/foo.exe

### Analysis

https://github.com/dotnet/msbuild/blob/863209471a60e9dfd387ed54d4edb85fd8db57ee/src/Utilities/TaskItem.cs#L80

There is no way to tell either: 1) That you _don't_ want normalisation of directory separator characters, or 2) which style of normalisation you want

### Versions & Configurations

dotnet msbuild --version
17.11.0.25706

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.