nuget dll is used by another process

心已入冬 提交于 2021-01-28 08:23:05

问题


I have the error from below and I'm quite out of ideas how to solve it. Tried the following until now:

  1. Clean bin/obj/packages/packages cache
  2. Remove manually from csproj and packages files the package and add it afterwards..still error
  3. Update Visual Studio 2017
  4. Reinstall Visual Studio 2017
  5. Trace which processes are using a file with name that contains Newtonsoft
  6. Copy the solution from another laptop where the builds works just fine

Yet, after all from above, I still get:

Error       NuGet Package restore failed for project DriversApp.Android: Unable to find version '10.0.3' of package 'Newtonsoft.Json'.
  C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\: Package 'Newtonsoft.Json.10.0.3' is not found on source 'C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\'.
  https://api.nuget.org/v3/index.json: Error downloading 'Newtonsoft.Json.10.0.3' from 'https://api.nuget.org/v3-flatcontainer/newtonsoft.json/10.0.3/newtonsoft.json.10.0.3.nupkg'.
  The process cannot access the file 'C:\Users\user\.nuget\packages\newtonsoft.json\10.0.3\lib\netstandard1.0\Newtonsoft.Json.dll' because it is being used by another process.
. Please see Error List window for detailed warnings and errors.                

How to get this solved? I got really stuck on this one...


回答1:


After a lot of investigation and ideas, I've solved this by uninstalling the antivirus solution as the rules added by me within my laptop were overrode by the company server policies.

As a conclusion, first check your antivirus solution, and if you are within a controlled environment, make sure your rules are not overrode by company server policies.

Thank you, @Leo Liu-MSFT for the assistance.




回答2:


nuget dll is used by another process

You can try to use following troubleshooting to resolve this issue.

  1. In Windows Explorer go to the folder where the NuGet packages are installed C:\Users\user\.nuget\packages, deleted the Newtonsoft.Json folders.

  2. May it has something to do with the same package being referenced in multiple projects within the same solution, adding "-DisableParallelProcessing" to the nuget restore command, the final command would look like:

    nuget restore "%WORKSPACE%\Solutions\App\App.sln" -DisableParallelProcessing

  3. Excluding NuGet package files from the anti-malware products, or try to disable the antivirus. The anti-malware/antivirus products briefly locking these files during the NuGet restore operations.

  4. Clear all referenced libraries before build the project by right click to Solution in solution explorer after click to "Clean Solution".




回答3:


Most probably I was faced when there is some other error in the project (ie: project reference error etc.)

try 0: Remove all bin & obj from all project.

Try 1: Restart PC

Try 2: close vs & %temp% delete all

Try 3: Disable antivirus for the moment

Try 4: Change Debug to Release and revert back

Try 5: Clear All nuget caches

If above nothing works then shut down your pc, sit back for moments, relax and then check back.




回答4:


Run this command with admin rights (net session /delete). It worked for me.



来源:https://stackoverflow.com/questions/49202946/nuget-dll-is-used-by-another-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!