Docker Container Build : (Cleanup Temporary Target Assembly target) -> C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.WinFx.targets(480,10): error MSB3061: Unable to delete file obj\x86\Release\. Access to the path is denied

MVAAnand 0 Reputation points

I have a solution targetting .netframework 3.5 and getting build in VS2019.

I am able to build the solution using msbuild. Now days I am trying to create a image to build project successfully inside the container.

My DockerFile looks like as given below:

# escape=`

# Use a specific tagged image. Tags can be changed, though that is unlikely for most images.
# You could also use the immutable tag @sha256:324e9ab7262331ebb16a4100d0fb1cfb804395a766e3bb1806c62989d1fc1326

# Restore the default Windows shell for correct batch processing.
SHELL ["cmd", "/S", "/C"]

COPY ["Component Factory", "C:\\Program Files (x86)\\Component Factory\\"]

# Install .NET Fx 3.5
RUN curl -fSLo `
    && tar -zxf `
    && del /F /Q `
    && DISM /Online /Quiet /Add-Package /PackagePath:.\ `
    && del `
    && powershell Remove-Item -Force -Recurse ${Env:TEMP}\*

# Copy our Install script.
COPY Install.cmd C:\TEMP\

# Download collect.exe in case of an install failure.
ADD C:\TEMP\collect.exe

# Use the latest release channel. For more control, specify the location of an internal layout.
ADD ${CHANNEL_URL} C:\TEMP\VisualStudio.chman

    # Download the Build Tools bootstrapper.
    curl -SL --output vs_buildtools.exe `
    # Install Build Tools with the Microsoft.VisualStudio.Workload.AzureBuildTools workload, excluding workloads and components with known issues.
    && (call C:\TEMP\Install.cmd vs_buildtools.exe --quiet --wait --norestart --nocache install `
        --installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\BuildTools" `
        --channelUri C:\TEMP\VisualStudio.chman `
        --installChannelUri C:\TEMP\VisualStudio.chman `
        --add Microsoft.VisualStudio.Workload.ManagedDesktopBuildTools;includeRecommended;includeOptional `
        --add Microsoft.VisualStudio.Workload.VCTools;includeRecommended `
        --add Microsoft.Component.MSBuild `
        --add Microsoft.VisualStudio.Component.VC.CoreBuildTools `
        --add Microsoft.VisualStudio.Component.VC.ATLMFC `
        --add Microsoft.VisualStudio.ComponentGroup.VC.Tools.142.x86.x64 `
        --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 `
        --add Microsoft.VisualStudio.Component.VC.ATL) `
    # Cleanup
    && del /q vs_buildtools.exe

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
# Define the entry point for the Docker container.
# This entry point starts the developer command prompt and launches the PowerShell shell.
ENTRYPOINT ["C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\Common7\\Tools\\VsDevCmd.bat", "&&", "powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]

But build is getting failed saying

(CleanupTemporaryTargetAssembly target) ->
  C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.WinFx.targets(480,10): error MSB3061: Unable to delete file "obj\x86\Release\TestA.dll". Access to the path 'C:\src\Repo\TestProject\obj\x86\Release
\TestA.dll' is denied. [C:\src\Repo\TestProject\TestA.csproj]

I tried to delete within container also, its not allowed. There have been discussion around the similar problem but couldn't get concrete root cause and solution. Specially when I am able to build it using outside the container.

Windows Server 2019
Windows Server 2019
A Microsoft server operating system that supports enterprise-level management updated to data storage.
3,541 questions
{count} votes