Visual Studio – Build – Error – “Exception: The process cannot access the file – obj’ because it is being used by another process.

Background

Ran into a little error while trying to build a Visual Studio Project.

Error

Error Item

Image

itisbeingusedbyanotherprocess.20200128.0141PM.PNG

Textual

Executing Clean
Removing bin,obj directories
Error: 1/28/2020 1:03:28 PM:
At C:\app\app-master\build\buildtasks.ps1:23 char:50 + ... -ChildItem -Recurse bin, obj -Directory | Remove-Item -Recurse -Force +                                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~ [<>] Exception: The process cannot access the file 'C:\appd\app-master\src\app\obj' because it is being used by another process.

TroubleShooting

Outline

  1. Trigger
    • PowerShell
      • build\buildtasks.ps1
        • Get-ChildItem -Recurse bin, obj -Directory | Remove-Item -Recurse -Force
  2. Tools
    • Identify which processes are using the targeted folder
      • Microsoft
        • SysInternals
          • handle

Trigger

Powershell

build\buildtasks.ps1

The buildtasks.ps1 script issues this command :-

Get-ChildItem -Recurse bin, obj -Directory | Remove-Item -Recurse -Force

The statement recursively removes folders from the targeted build folder.

Tools

Microsoft

SysInternals

handle

Artifacts

SysInternals Handle is available here.

Syntax

handle.exe [filename]

Sample
handle.exe "\obj"
Output

sysinternals.handle.obj.01.20200128.0145PM

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s