I was trying to build a Universal App by using a TFS build agent. It fails with the following exception:
Microsoft.AppXPackage.Targets(2883,5): error MSB3231: Unable to remove directory “obj\x64\Release\PackageUploadLayout\”. Access to the path denied
I solved that by deleting the PackageUploadLayout directory by a script added to the Pre-Build event of the Visual Studio Project. The script deletes every sub folder of the solution with that name.
cd /d $(SolutionDir) for /d /r . %%d in (PackageUploadLayout) do @if exist "%%d" rd /s/q "%%d"