Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnet publish inside WSL cannot handle read only files which are copied to the output path #44053

Open
mdisg opened this issue Oct 10, 2024 · 0 comments
Assignees
Labels
Area-NetSDK needs team triage Requires a full team discussion

Comments

@mdisg
Copy link

mdisg commented Oct 10, 2024

Describe the bug

We are using WSL to publish our solution with R2R enabled for linux systems (arm / x64). The project is maintained using Microsoft TFS and the directory/files are not inside the WSL file system but accessed via mount point to the windows file system (/mnt/d/).
Our projects contain some files like appsettings.json or binary files which should only copied to the output directory. These files do have the read only flag set on the windows file system as they are tracked by the TFS source control. If there is no pending edit, they are read only.

This does also affect referenced (3rd party) managed assemblies

When using the .NET 6 SDK as we did the past years all works as expected. We publish using these command:
dotnet publish -r linux-x64 --self-contained false -c Release_R2R -o /mnt/d/publish /mnt/d/solution/solution.sln

When using the .NET 8 SDK this failes with the following error message:
sdk8/sdk/8.0.402/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Publish.targets(351,5): error MSB3021: Unable to copy file "/mnt/d/solution/project/appsettings.json" to "/mnt/d/publish/appsettings.json". Access to the path '/mnt/d/publish/appsettings.json' is denied. [/mnt/d/projects/solution/project/project.csproj

We use these command to publish using .NET SDK 8
dotnet publish -r linux-x64 --self-contained false -c Release_R2R --property:PublishDir=/mnt/d/publish /mnt/d/solution/solution.sln

When looking at the publish output path from inside the WSL the appsettings.json does get the permissions -r-xr-xr-x and has zero bytes.
So the file is created but publish failes to write to it as the write permission is missing. For me it looks like a new file is being created and the SDK wants to copy the content of the source file to the new file. I don't understand why the file itself is not copied directly. If I copy the file manually using cp it works as expected.

This is my wsl.conf which looks correct for me

[automount]
enabled=true
options=metadata,uid=1000,gid=1000,umask=022

So to get it work we could change the file permision before building but as the file is under source control (TFS) that is not a ideal solution as the file would then be writable but not tracked as pending change. Copying the whole solution directory into the WSL file system before publish is also not a acceptable solution because our solution is big. This would mean to copy hundreds of megabyte.

Is this a bug in the SDK or am I doing anything wrong?

To Reproduce

I created a small sample solution/project which you can find here https://github.com/mdisg/WslPublishTest
To reproduce the windows file permission of the file SomeFile.txt must be set to read only.

The following sdk6 publish command works as expected:
dotnet publish -r linux-x64 --self-contained false -c Release_NET6 -o <publish path> <path to solution>/WslPublishTest.sln

The following sdk8 publish command fails with the access denied error:
dotnet publish -r linux-x64 --self-contained false -c Release --property:PublishDir=<publish path> <path to solution>/WslPublishTest.sln

Further technical details

Output of dotnet --info for SDK 6

.NET SDK (reflecting any global.json):
 Version:   6.0.427
 Commit:    93fddcf4f6

Runtime Environment:
 OS Name:     debian
 OS Version:  11
 OS Platform: Linux
 RID:         debian.11-x64
 Base Path:   /mnt/d/Storage/dotnet/sdk6/sdk/6.0.427/

global.json file:
  Not found

Host:
  Version:      6.0.35
  Architecture: x64
  Commit:       b357f86ce3

.NET SDKs installed:
  6.0.427 [/mnt/d/Storage/dotnet/sdk6/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.35 [/mnt/d/Storage/dotnet/sdk6/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.35 [/mnt/d/Storage/dotnet/sdk6/shared/Microsoft.NETCore.App]

Output of dotnet --info for SDK 8

.NET SDK:
 Version:           8.0.402
 Commit:            70aa751718
 Workload version:  8.0.400-manifests.b6724b7a
 MSBuild version:   17.11.4+37eb419ad

Runtime Environment:
 OS Name:     debian
 OS Version:  11
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /mnt/d/Storage/dotnet/sdk8/sdk/8.0.402/

.NET workloads installed:
Configured to use loose manifests when installing new manifests.
There are no installed workloads to display.

Host:
  Version:      8.0.8
  Architecture: x64
  Commit:       08338fcaa5

.NET SDKs installed:
  8.0.402 [/mnt/d/Storage/dotnet/sdk8/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.8 [/mnt/d/Storage/dotnet/sdk8/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 8.0.8 [/mnt/d/Storage/dotnet/sdk8/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-NetSDK untriaged Request triage from a team member labels Oct 10, 2024
@MiYanni MiYanni added type-investigation needs team triage Requires a full team discussion and removed untriaged Request triage from a team member type-investigation labels Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-NetSDK needs team triage Requires a full team discussion
Projects
None yet
Development

No branches or pull requests

2 participants