Sdk: ResolvePackageFileConflicts fails when paths have New Line characters

Created on 25 Aug 2017  Β·  11Comments  Β·  Source: dotnet/sdk

NewLine characters in HintPaths are causing an exception in ResolvePackageFileConflicts for projects that previously worked. E.g.

<Reference Include="System.Collections.Immutable, Version=1.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
      <HintPath>
      ..\..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll
      </HintPath>
</Reference>

StackTrace:

The "ResolvePackageFileConflicts" task failed unexpectedly.
System.ArgumentException: Illegal characters in path.
   at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
   at System.IO.Path.GetFileName(String path)
   at Microsoft.NET.Build.Tasks.ItemUtilities.GetTargetPath(ITaskItem item)
   at Microsoft.NET.Build.Tasks.ItemUtilities.GetReferenceTargetPath(ITaskItem item)
   at Microsoft.NET.Build.Tasks.ConflictResolution.ResolvePackageFileConflicts.<>c.<ExecuteCore>b__35_1(ConflictItem ci)
   at Microsoft.NET.Build.Tasks.ConflictResolution.ConflictResolver`1.ResolveConflicts(IEnumerable`1 conflictItems, Func`2 getItemKey, Action`1 foundConflict, Boolean commitWinner, Action`1 unresolvedConflict)
   at Microsoft.NET.Build.Tasks.ConflictResolution.ResolvePackageFileConflicts.ExecuteCore()
   at Microsoft.NET.Build.Tasks.TaskBase.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() Services (Services\Services)            

Reports:

/cc @dsplaisted

Bug

Most helpful comment

Projects like this used to work and now don't, so I think it will be causing people pain.

If it is desired behaviour, then maybe an improved error message would be a decent compromise?

This could detail the reference that has the problem, which would be a big help while fixing up.

All 11 comments

@rainersigwald i think MsBuild simply see it as there is a new line in the middle. Is that intended? I can see the benefit of not using &#xD; all the time

Projects like this used to work and now don't, so I think it will be causing people pain.

If it is desired behaviour, then maybe an improved error message would be a decent compromise?

This could detail the reference that has the problem, which would be a big help while fixing up.

@wli3 you could just add a Trim() to GetTargetPath

@wli3 this seems simple enough. I will mark it for 2.1.3xx, any chance you can get this in in between your other stuff?

I cannot repo it with 2.1.4xx branch master.

My test csproj is the following and I just run _dotnet build_ against it. @dsplaisted do you know anything else I need to repo this?

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Library</OutputType>
    <TargetFramework>net462</TargetFramework>
  </PropertyGroup>
  <ItemGroup />
  <ItemGroup>
    <Reference Include="System.Collections.Immutable">
      <HintPath>
      ..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll
      </HintPath>
    </Reference>
  </ItemGroup>
</Project>

tree /f

C:.
β”‚   NETFrameworkLibrary.cs
β”‚   NETFrameworkLibrary.csproj
β”‚
β”œβ”€β”€β”€bin
β”‚   └───Debug
β”‚       └───net462
β”‚               NETFrameworkLibrary.dll
β”‚               NETFrameworkLibrary.pdb
β”‚               System.Collections.Immutable.dll
β”‚               System.Collections.Immutable.xml
β”‚
β”œβ”€β”€β”€obj
β”‚   β”‚   NETFrameworkLibrary.csproj.nuget.cache
β”‚   β”‚   NETFrameworkLibrary.csproj.nuget.g.props
β”‚   β”‚   NETFrameworkLibrary.csproj.nuget.g.targets
β”‚   β”‚   project.assets.json
β”‚   β”‚
β”‚   └───Debug
β”‚       └───net462
β”‚               NETFrameworkLibrary.AssemblyInfo.cs
β”‚               NETFrameworkLibrary.AssemblyInfoInputs.cache
β”‚               NETFrameworkLibrary.assets.cache
β”‚               NETFrameworkLibrary.csproj.CopyComplete
β”‚               NETFrameworkLibrary.csproj.CoreCompileInputs.cache
β”‚               NETFrameworkLibrary.csproj.FileListAbsolute.txt
β”‚               NETFrameworkLibrary.csprojAssemblyReference.cache
β”‚               NETFrameworkLibrary.dll
β”‚               NETFrameworkLibrary.pdb
β”‚
└───packages
    └───system.collections.immutable.1.3.1
        β”‚   dotnet_library_license.txt
        β”‚   System.Collections.Immutable.nuspec
        β”‚   ThirdPartyNotices.txt
        β”‚   [Content_Types].xml
        β”‚
        β”œβ”€β”€β”€lib
        β”‚   β”œβ”€β”€β”€netstandard1.0
        β”‚   β”‚       System.Collections.Immutable.dll
        β”‚   β”‚       System.Collections.Immutable.xml
        β”‚   β”‚
        β”‚   └───portable-net45%2Bwin8%2Bwp8%2Bwpa81
        β”‚           System.Collections.Immutable.dll
        β”‚           System.Collections.Immutable.xml
        β”‚
        β”œβ”€β”€β”€package
        β”‚   └───services
        β”‚       └───metadata
        β”‚           └───core-properties
        β”‚                   29d09ebac0cf450d9158528bb737fd76.psmdcp
        β”‚
        └───_rels
                .rels

@wli3 I'm not sure, try changing the TargetFramework to netcoreapp2.0 and seeing what happens.

I can repo with msbuid /t:build

Further root cause

run the same code on fullframework and dotnet core
c# Path.GetFileName("\r\n net461\\lib\\System.Net.Http.dll\r\n");
fullframework throws but core is good

Core GetFileName don't check Path.GetInvalidPathChars()

https://github.com/dotnet/cli/issues/4523 similar to Nuget we should trim our own

Was this page helpful?
0 / 5 - 0 ratings