46

When I try to pack my MVC project (NuGet.exe pack) I get:

NuGet.exe : Access to the path '...' is denied.

This happens to be the case for all files in the content and script folder of my MVC solution. If I remove the readonly flag on all these files NuGet.exe is able to create the NuGet package.

Why do I have to remove the readonly flag? Is there another way?

I'm using TFS which specify the readonly flag on all files under source control.

I am running:

  • NuGet Version: 1.7.30402.9028
  • Microsoft Visual Studio 2010 Version 10.0.40219.1 SP1Rel

I'm using the NuGet.exe that you get when you install the NuGet package NuGet.CommandLine which is located at http://nuget.org/packages/NuGet.CommandLine.

knut
  • 4,699
  • 4
  • 33
  • 43

10 Answers10

35

Apparently, you need to set ReadOnly=false for the files it accesses

TJB
  • 13,367
  • 4
  • 34
  • 46
  • The link mentions upgrade and uninstall. It also states that it has to do with offline mode. The question is about _packing_ in online mode. – knut Nov 08 '12 at 18:35
  • Hmm, good point, I realize the question is about packing (I had the same issue) maybe we need to open another issue on NuGet regarding this specifically. – TJB Nov 08 '12 at 22:51
  • +1 I had similar issue when I was applying packages to projects via "Manage Solution packages". Your solution helped. – InspiredBy Apr 25 '13 at 20:44
  • Also putting packages under TFS source control also makes them read-only, which leads to this error. – Jalal Oct 08 '17 at 10:52
17

Try running it as administrator.

ATL_DEV
  • 9,256
  • 11
  • 60
  • 102
8

I ran into this with nuget restore after doing a git clean -fd with VisualStudio open: the packages/ directory was marked for deletion, and while several files were deleted, the packages/ folder itself was not as VisualStudio had the .nupkg files open.

Once I closed VisualStudio and re-ran git clean, it removed the packages/ directory and then nuget was able to restore everthing correctly.

gregmac
  • 24,276
  • 10
  • 87
  • 118
2

In my case something happened when switching branch in git. Everyone lost execute permissions for Nuget.exe.

This blog post helped me: http://mannysiddiqui.wordpress.com/2013/05/11/nuget-access-is-denied-command-existed-with-code-5/

Fredrik Stolpe
  • 881
  • 10
  • 14
2

I was running into a similar problem. I attempted to restart Visual Studio, Run as Administrator (Which I always do), Set the folder attributes to ensure the 'Read-Only' flag was off. Regardless, whatever I did, I still encountered the error "access to the path is denied" when updating my Nu-Get packages.

I was able to fix the issue by updating packages one-by-one. Choosing instead to go through each dependency and updating it. Once the dependency was updated I would choose another, sometimes the same error resulted in which case I would choose another until all my packages were successfully updated.

It appears in my case the Nu-Get packages had to be updated in a particular order.

Hope this helps someone out there

BDarley
  • 697
  • 1
  • 10
  • 19
1

I had this problem and it turned out windows had an update waiting for the next restart. Cleared with no problem after restarting and waiting for the update.

Dpedrinha
  • 3,741
  • 3
  • 38
  • 57
0

My collegue just got this error, during all "worked on my machine". After some research I found out that the *.nuspec file for some reason wasn't added to the version control.

python_kaa
  • 1,034
  • 13
  • 27
0

In order to Restore nuget packages, remove read only permissions from the folder level (for windows). Clean the solution and Build. It will works

0

In my case it was *.gitattributes in the git repo root recently modified (incorrectly), so git started to checkout nuget.exe on the build server and converted all LF to CRLF inside, making it non-executable.

v.karbovnichy
  • 3,183
  • 2
  • 36
  • 47
-2

Run your Visual Studio with administrator rights.

Cas
  • 11