The Error
When attempting to publish the app in the microsoft .NET 6.0 sdk container, the build fails with the following error:
System.IO.IOException: The process cannot access the file '/app/My-App/web.config' because it is being used by another process.
The failure occurs right after or towards the end of the React-JS frontend creation.
Here is the error in full:
#25 253.0 /usr/share/dotnet/sdk/6.0.401/Sdks/Microsoft.NET.Sdk.Publish/targets/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018: The "TransformWebConfig" task failed unexpectedly. [/app/My-App/My-App.csproj]
#25 253.0 /usr/share/dotnet/sdk/6.0.401/Sdks/Microsoft.NET.Sdk.Publish/targets/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018: System.IO.IOException: The process cannot access the file '/app/My-App/web.config' because it is being used by another process. [/app/My-App/My-App.csproj]
#25 253.0 /usr/share/dotnet/sdk/6.0.401/Sdks/Microsoft.NET.Sdk.Publish/targets/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018: at Microsoft.Win32.SafeHandles.SafeFileHandle.Init(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize) [/app/My-App/My-App.csproj]
#25 253.0 /usr/share/dotnet/sdk/6.0.401/Sdks/Microsoft.NET.Sdk.Publish/targets/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018: at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize) [/app/My-App/My-App.csproj]
#25 253.0 /usr/share/dotnet/sdk/6.0.401/Sdks/Microsoft.NET.Sdk.Publish/targets/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018: at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite) [/app/My-App/My-App.csproj]
#25 253.0 /usr/share/dotnet/sdk/6.0.401/Sdks/Microsoft.NET.Sdk.Publish/targets/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018: at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite) [/app/My-App/My-App.csproj]
#25 253.0 /usr/share/dotnet/sdk/6.0.401/Sdks/Microsoft.NET.Sdk.Publish/targets/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018: at Microsoft.NET.Sdk.Publish.Tasks.TransformWebConfig.Execute() [/app/My-App/My-App.csproj]
#25 253.0 /usr/share/dotnet/sdk/6.0.401/Sdks/Microsoft.NET.Sdk.Publish/targets/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/app/My-App/My-App.csproj]
#25 253.0 /usr/share/dotnet/sdk/6.0.401/Sdks/Microsoft.NET.Sdk.Publish/targets/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(50,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/app/My-App/My-App.csproj]
------
executor failed running [/bin/sh -c dotnet publish "My-App/My-App.csproj" -c Release -o /app/My-App]: exit code: 1
Dockerfile
Here is the relevant part of my Dockerfile. Since it is the build container, not much effort is made to keep it small.
Note that the build worked fine in a .NET 2.2 docker build using mcr.microsoft.com/dotnet/core/sdk:2.2
. The errors only appeared after the migration to mcr.microsoft.com/dotnet/sdk:6.0
# ========= Build ASP.NET Core =========
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS dotnet_backend_build
RUN apt update && apt upgrade -y
RUN apt install -y curl wget make g++
# ========== Install Node ==========
RUN curl --silent --location https://deb.nodesource.com/setup_lts.x | bash -
RUN apt install -yq --no-install-recommends build-essential nodejs
# Node needs more memory during buildtime than default (=512)
ARG NODE_OPTIONS="--max-old-space-size=4096"
# ========= Installed Node =========
WORKDIR /app
COPY . .
RUN dotnet restore "./My-App/My-App.csproj"
RUN dotnet publish "My-App.csproj" -c Release -o /My-App/My-App
# ========= Built ASP.NET Core =========
What I've tried so far
- Compilation on my local windows machine using MSBuild works fine.
- dotnet publish Error: The process cannot access the file because it is being used by another process -> Not applicable, since I cannot run on a local machine
- Add the command
RUN dotnet build-server shutdown
to line beforedotnet publish
- On a wild guess this solution The "TransformWebConfig" task failed unexpectedly - System.Exception: The acceptable value for AspNetCoreModuleHostingModel property is either
- Copied the My-App.csproj to a separate layer before restoring, as seen in the Microsoft tutorial: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/docker/building-net-docker-images?view=aspnetcore-6.0#the-dockerfile
- Another promising option was this MSBuild error MSB4018 cannot access project.assets.json in NET 5 build However, since I am using the microsoft .NET 6 docker image, are MSBuild options even possible? I did not find the option in the dotnet publish documentation: https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-publish Passing on the arguments -m -graph resulted in the same error message
- In order to prevent timing issues, activate verbose logging as seen here: https://github.com/NuGet/Home/issues/11607 -> Added flag
-v d
to dotnet publish command. This results in presumably the same issue, but the output is clipped by docker due to a too high console log rate
I would appreciate any further pointers. Thank you in advance.