Possible to-do’s that can fix, “Restore Nuget failed, process busy!”


Stuck while restoring Nuget packages? Well, there can be a multitude of reasons for the failure of the restoration of nuget packages. One of many is “because it is being used by another process.”

and you might end up with something similar on the error list:

ERROR:
error: error while writing anim: obj\Debug\android\bin\classes\android\support\design\R$anim.class (The process cannot access the file because it is being used by another process)

FILENAME:
public static final class anim {MyNameSpace.Mobile.Droid X:\..Path..\MyNameSpace.Mobile\MyNameSpace.Mobile.Droid\obj\Debug\android\src\android\support\design\R.java 

The process cannot access the file ‘R$anim.class’ because it is being used by another process. MyNameSpace.Mobile.Droid

or

NuGet Package restore failed: Microsoft.Bcl.Build.Tasks.dll used by another process

NuGet Package restore failed for project MyProject.Application: The process cannot access the file ‘C:\MySolution\packages\Microsoft.Bcl.Build.1.0.21\build/Microsoft.Bcl.Build.Tasks.dll’ because it is being used by another process..

1

So let’s get started,

0. Clean and Rebuild

Clean your solution and rebuild it.
Doesn’t help?
Close Visual Studio > delete the bin and obj folders > reopen Visual Studio > clean the Solution > Rebuild it.

1. Shutdown and Reboot your machine.

Yeah, this sounds lame to do but since “The process cannot access the file “xyz” because it is being used by another process” let us try to kill the process.

  1. First, close all instances of visual studio and re-open the project in which you need to restore the nugets.
  2. If that worked, great. If it didn’t?
    open the old friend ‘Task Manager’  Find msbuild.exe & devenv.exe in process explorer and kill it.
  3. “Shutdown” (not Restart). let it rest for a second and then turn it on again.

that was the easiest thing to do if that didn’t help try the other.

2. Remapping

If you are using some source control try remapping the local directory of the solution. possibly when the repository is being remapped Visual Studio will automatically restore the nugets for the new location.

And since the issue was at obj\Debug\ and we have just remapped but haven’t built the project yet the obj and bin are not generated so far.

Rebuilding the solution should do the thing now!

3. Tweaking out the Extensions folder.

This is the last possible thing that helped me out. We are going to play with the extensions folder and move/rename files here and there.  Taking backup is the least I can advise.

  1. Remove the bin and obj folders from all the client projects and PCL.
    Removing bin and obj folders from PCL

    Removing bin and obj folders from PCL

    Removing bin and obj folders from Client Projects

    Removing bin and obj folders from all the Client Projects

  2. Take a backup of your extensions folder and rename it/ or move it to some other directory. The extensions folder can be found at

    C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\  Extensions

    Rename Extensions Folder

  3. Now open Visual Studio and Clean the Solution.
  4. Restore Nuget Packages for the solution.
  5. Rebuild. (prefer rebuilding each project one-by-one)

This should get the things going.

I cannot commit you that this will get you through in all cases but in most of them, yes! if it happens it does not and something else does? please comment the solution other than these, it might help someone else 🙂 

Pingback for assistance, your Feedback’s are always a welcome… 🙂

Regards,
Aditya Deshpande

Leave a Reply

Fill in your details below or click an icon to log in:

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