dotnet/sdk

ProduceContentAssets should not "url decode" paths provided by NuGet

nkolev92 opened this issue · 2 comments

Create the following project and run dotnet build.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net462</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="ContentFilesExample" Version="*" />
  </ItemGroup>

</Project>

Make sure that nuget.org is among the sources.

 dotnet build
Microsoft (R) Build Engine version 16.0.450+ga8dc7f1d34 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 530.45 ms for C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\ContentFilesExampleTest\ContentFilesExampleTest.csproj.
C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(350,5): error MSB4018: The "ProduceContentAssets" task failed unexpectedly. [C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\ContentFilesExampleTest\ContentFilesExampleTest.csproj]
C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(350,5): error MSB4018: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\globalPackagesFolder\contentfilesexample\1.0.2\contentFiles\cs\portable-net45+wpa81+wp8+win8\ExampleReader.cs.pp'. [C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\ContentFilesExampleTest\ContentFilesExampleTest.csproj]
C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(350,5): error MSB4018:    at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle) [C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\ContentFilesExampleTest\ContentFilesExampleTest.csproj]
C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(350,5): error MSB4018:    at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options) [C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\ContentFilesExampleTest\ContentFilesExampleTest.csproj]
C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(350,5): error MSB4018:    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) [C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\ContentFilesExampleTest\ContentFilesExampleTest.csproj]
C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(350,5): error MSB4018:    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) [C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\ContentFilesExampleTest\ContentFilesExampleTest.csproj]
C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(350,5): error MSB4018:    at System.IO.File.OpenRead(String path) [C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\ContentFilesExampleTest\ContentFilesExampleTest.csproj]
C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(350,5): error MSB4018:    at Microsoft.NET.Build.Tasks.NugetContentAssetPreprocessor.Process(String originalAssetPath, String relativeOutputPath, String& pathToFinalAsset) [C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\ContentFilesExampleTest\ContentFilesExampleTest.csproj]
C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(350,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ProduceContentAssets.ProduceContentAsset(ITaskItem contentFile) [C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\ContentFilesExampleTest\ContentFilesExampleTest.csproj]
C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(350,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ProduceContentAssets.ExecuteCore() [C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\ContentFilesExampleTest\ContentFilesExampleTest.csproj]
C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(350,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute() [C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\ContentFilesExampleTest\ContentFilesExampleTest.csproj]
C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(350,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\ContentFilesExampleTest\ContentFilesExampleTest.csproj]
C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(350,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\ContentFilesExampleTest\ContentFilesExampleTest.csproj]

Build FAILED.

C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(350,5): error MSB4018: The "ProduceContentAssets" task failed unexpectedly. [C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\ContentFilesExampleTest\ContentFilesExampleTest.csproj]
C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(350,5): error MSB4018: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\globalPackagesFolder\contentfilesexample\1.0.2\contentFiles\cs\portable-net45+wpa81+wp8+win8\ExampleReader.cs.pp'. [C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\ContentFilesExampleTest\ContentFilesExampleTest.csproj]
C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(350,5): error MSB4018:    at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle) [C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\ContentFilesExampleTest\ContentFilesExampleTest.csproj]
C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(350,5): error MSB4018:    at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options) [C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\ContentFilesExampleTest\ContentFilesExampleTest.csproj]
C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(350,5): error MSB4018:    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) [C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\ContentFilesExampleTest\ContentFilesExampleTest.csproj]
C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(350,5): error MSB4018:    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) [C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\ContentFilesExampleTest\ContentFilesExampleTest.csproj]
C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(350,5): error MSB4018:    at System.IO.File.OpenRead(String path) [C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\ContentFilesExampleTest\ContentFilesExampleTest.csproj]
C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(350,5): error MSB4018:    at Microsoft.NET.Build.Tasks.NugetContentAssetPreprocessor.Process(String originalAssetPath, String relativeOutputPath, String& pathToFinalAsset) [C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\ContentFilesExampleTest\ContentFilesExampleTest.csproj]
C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(350,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ProduceContentAssets.ProduceContentAsset(ITaskItem contentFile) [C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\ContentFilesExampleTest\ContentFilesExampleTest.csproj]
C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(350,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ProduceContentAssets.ExecuteCore() [C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\ContentFilesExampleTest\ContentFilesExampleTest.csproj]
C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(350,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute() [C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\ContentFilesExampleTest\ContentFilesExampleTest.csproj]
C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(350,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\ContentFilesExampleTest\ContentFilesExampleTest.csproj]
C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(350,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [C:\Users\nikolev.REDMOND\Source\Repos\ContentFilesExampleTest\ContentFilesExampleTest\ContentFilesExampleTest.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:01.67

The issue here is that the selected framework for the contentfiles is a PCL framework and + in the name, encoded as %2B.

NuGet extracts the encoded name, and writes that to the assets file, g.props as needed.

Paths that the targets read from NuGet should be treated as strings and not decoded in any way.

The item comes out of ResolvePackageAssets with the decoded path.

We may need to escape output items from ResolvePackageAssets to ensure MSBuild doesn't decode any paths from the assets file.

Why does NuGet support portable-x%2By as a spelling of portable-x+y?