Fix relative path handling on Windows.#7842
Conversation
|
@peterhuene, It will cover your contributions to all .NET Foundation-managed open source projects. |
|
@peterhuene, thanks for signing the contribution license agreement. We will now validate the agreement and then the pull request. |
|
I haven't reviewed this in detail yet, but my first thought is whether we can now make use of dotnet/corefx#11689 cc @JeremyKuhne |
|
That would be great to remove this helper in favor of a framework method. |
|
Definitely would be good to use the framework method or at least copy the code if you can't for some reason. If you find any issues with the algorithm let me know. |
|
I'll amend the commit with the proposed change. |
|
@JeremyKuhne there were two places in the codebase I wasn't able to move to The places where I could do so, I replaced with calls to |
@nguerrera any guidance on this one? |
|
Hmm, as far as I can tell, dotnet-cli-build should work fine since it targets $(CliTargetFramework) == netcoreapp2.1. Also, We probably don't even need a MakeRelative build task because msbuild has https://msdn.microsoft.com/en-us/library/dd633440.aspx#BKMK_MakeRelative there instead.) TestFramework is more interesting because it's netstandard and there's no netstandard version with Path.GetRelativePath. I'm looking at the code to understand if the tests really need this or if we can achieve what it's doing in a simpler way. |
|
Oh, I see MakeRelative task is a workaround for a bug in MSBuild::MakeRelative on x-plat, so never mind that change. I'm still not seeing why we can't use Path.GetRelativePath in dotnet-cli-build. What is the error when you try to do that? We can leave the TestFramework usage alone and your fix in Cli.Utils. We're going to be trimming down Cli.Utils at some point soon and cleaning that up can be part of that. |
I see it getting built for |
|
Looking deeper, it's oddly getting built for netcoreapp2.1, but without an appropriately recent reference to Microsoft.NETCore.App. I think some build refactoring caused this project to inherit DisableImplicitFrameworkReferences=true. If you add the following to dotnet-cli-build.csproj (like other TargetFramework=$(CliTargetFramework) in the tree), it should work: <PackageReference Include="Microsoft.NETCore.App" Version="$(CLI_SharedFrameworkVersion)" /> |
|
I'll modify the project and see if I can get it building; as |
On Windows, `PathUtility.GetRelativePath` was not properly handling paths that differed by case in the drive reference (e.g. "C:\" vs. "c:\"). The fix was to add the missing case-insensitive comparison argument. Replaced uses of `PathUtility.GetRelativePath` with `Path.GetRelativePath` where possible (requires 2.0.0+). Additionally, `PathUtility.RemoveExtraPathSeparators` was not handling paths with drive references on Windows. If the path contained a drive reference, the separator between the drive reference and the first part of the path was removed. This is due to `Path.Combine` not handling this case, so an explicit concatenation of the separator was added. This commit resolves issue #7699.
|
@nguerrera pushed the changes to the task. |
|
|
||
| var relativePathReferences = _appliedCommand.Arguments.Select((r) => | ||
| PathUtility.GetRelativePath(msbuildProj.ProjectDirectory, Path.GetFullPath(r))) | ||
| Path.GetRelativePath(msbuildProj.ProjectDirectory, Path.GetFullPath(r))) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| var relativePath = GetRelativePath(Path1, Path2, SeparatorChar); | ||
|
|
||
| RelativePath = ToTaskItem(Path1, Path2, relativePath); | ||
| RelativePath = ToTaskItem(Path1, Path2, Path.GetRelativePath(Path1, Path2)); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
On Windows,
PathUtility.GetRelativePathwas not properly handlingpaths that differed by case in the drive reference (e.g. "C:" vs.
"c:"). The fix was to add the missing case-insensitive comparison
argument.
Replaced uses of
PathUtility.GetRelativePathwithPath.GetRelativePathwhere possible (requires 2.0.0+).Additionally,
PathUtility.RemoveExtraPathSeparatorswas not handlingpaths with drive references on Windows. If the path contained a drive
reference, the separator between the drive reference and the first part
of the path was removed. This is due to
Path.Combinenot handlingthis case, so an explicit concatenation of the separator was added.
This commit resolves issue #7699.