microsoft / dotnet

This repo is the official home of .NET on GitHub. It's a great starting point to find many .NET OSS projects from Microsoft and the community, including many that are part of the .NET Foundation.
https://devblogs.microsoft.com/dotnet/
MIT License
14.43k stars 2.21k forks source link

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 #1381

Open MVAnand opened 1 year ago

MVAnand commented 1 year ago

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

ARG FROM_IMAGE=mcr.microsoft.com/windows/servercore:ltsc2019 FROM ${FROM_IMAGE}

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 microsoft-windows-netfx3.zip https://dotnetbinaries.blob.core.windows.net/dockerassets/microsoft-windows-netfx3-1809.zip && tar -zxf microsoft-windows-netfx3.zip && del /F /Q microsoft-windows-netfx3.zip && DISM /Online /Quiet /Add-Package /PackagePath:.\microsoft-windows-netfx3-ondemand-package~31bf3856ad364e35~amd64~~.cab && del microsoft-windows-netfx3-ondemand-package~31bf3856ad364e35~amd64~~.cab ` && 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 https://aka.ms/vscollect.exe C:\TEMP\collect.exe

Use the latest release channel. For more control, specify the location of an internal layout.

ARG CHANNEL_URL=https://aka.ms/vs/16/release/channel ADD ${CHANNEL_URL} C:\TEMP\VisualStudio.chman

RUN `

Download the Build Tools bootstrapper.

curl -SL --output vs_buildtools.exe https://aka.ms/vs/16/release/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';"] WORKDIR /src

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 outside the container in developer command prompt..

mairaw commented 1 year ago

Porque tantos testes @leonardoeliziario?