dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.73k stars 1.07k forks source link

Conflict between "pt-BR" and "pt-br" folders when publishing an ASP.NET application in Docker on Linux #43701

Open JuanDouglas opened 1 month ago

JuanDouglas commented 1 month ago

Description

When publishing an ASP.NET application in a Docker environment on Linux, there is a conflict between the pt-BR and pt-br folders. Dotnet automatically generates a folder named pt-br (lowercase), which is used by ASP.NET to locate language-specific libraries. However, when trying to copy the libraries during the publish process, dotnet assumes that the pt-BR (uppercase) folder has already been created, resulting in an error since Linux distinguishes between uppercase and lowercase in directory names.

This issue prevents the libraries from being copied to the correct folder, causing the publish process to fail.

Steps to reproduce:

  1. Create an ASP.NET Core project with a localized resource (Resources.pt-BR.resx).
  2. Include the NuGet package that contains resource files for the pt-BR folder.
  3. Publish the project in a Docker Linux environment.
  4. Observe the error during the library copy process to the pt-BR folder.

Expected behavior:

Dotnet should correctly differentiate between the pt-BR and pt-br folders in the Linux environment, creating or using the correct folder as expected by ASP.NET, without confusing the two directories.

Actual behavior:

Dotnet detects that the pt-br folder was created and assumes that the pt-BR folder already exists. However, since Linux differentiates between uppercase and lowercase in directory names, the pt-BR folder was not created, causing an error when trying to copy the files to that directory.

Error message:

The error message indicates that part of the copy directory has not been created yet, which is why the file copy operation was not completed.

/usr/share/dotnet/sdk/8.0.402/Sdks /Microsoft.NET.Sdk/targets/Microsoft.NET.Publish.targets(351,5): error MSB3021: Unable to copy file "/root/.nuget/packages/packagename/1.0.6.1/lib/net8.0/pt-BR/packagename.resources.dll" to "/app/publish/pt-BR/packagename.resources.dll". Could not find a part of the path '/app/publish/pt-BR/packagename.resources.dll'. [/app/project/project/project.csproj]

docker-error

Environment:

Operating System: Linux (Docker container mcr.microsoft.com/dotnet/sdk:8.0) Framework: .NET 8.0 ASP.NET Core 8.0 Docker version: 20.x.x

Possible solution:

A possible solution would be to adjust the publish process so that dotnet correctly creates or checks for the existence of resource folders, taking into account the case sensitivity of directory names on Linux file systems.

Current workaround:

As a temporary solution, the pt-BR folder can be manually created before publishing. However, this is not ideal for automated CI/CD pipelines. solução

KalleOlaviNiemitalo commented 1 month ago

In your current workaround, you create the pt-BR folder; but does the runtime then load the resource DLL from that folder or does it look in the pt-br folder only?

JuanDouglas commented 1 month ago

@KalleOlaviNiemitalo, sorry, the error does not occur at runtime but rather at publish time. Unfortunately, I have not been able to test the project in question within the environment to confirm, but I believe the reference is being loaded.

What makes it a bit strange is that no error occurs during the build (I was able to test the reference in the build, and it is working as it should).