'Nuget Package Restore Failing with Access to the path '..\packages\Microsoft.Owin.Security.Jwt\4.0.0' is denied

As title says I am getting that error while I am restoring my packages in Visual Studio 2015 Update 3, Windows 10 System.

Background: My company is maintaining a central nuget repository from where all the packages are being installed. The mentioned packages is a dependency to a package developed by my organization.

So I am using a solution .nuget package to specify our central repository to download all the packages even if it is coming from nuget.org. Everything is being served through that central repository. No direct nuget.org package url configuration in project.

Some Troubleshooting Information: I tried restoring packages directly from nuget it works without any issue.(No change in rights or project settings or system configuration)

Error Received during Restore:

NuGet Package restore failed for project projectName\project: Unable to find version '4.0.0' of package 'Microsoft.Owin.Security.Jwt'.
https://company-central-repository/nuget: Error downloading 'Microsoft.Owin.Security.Jwt.4.0.0' from 'https://company-central-repository/nuget/Download/Microsoft.Owin.Security.Jwt/4.0.0'. Access to the path '..\packages\Microsoft.Owin.Security.Jwt\4.0.0' is denied. https://company-central-repository/nuget-prerelease: Error downloading 'Microsoft.Owin.Security.Jwt.4.0.0' from 'https://company-central-repository/nuget-prerelease/Download/Microsoft.Owin.Security.Jwt/4.0.0'. Access to the path '..\packages\Microsoft.Owin.Security.Jwt\4.0.0' is denied.

I am not sure what is wrong with that.

My suspicion is that I am not able to download that package because I dont have access to that repository. Thats where access denied is coming from and not my local folder.

But I am able to search those packages through web portal of the repository and its visible and I am able to read the details. Also I am able to download the .package file.

Also I checked the rights of the folders 'C:\Users\username.nuget\packages' and project package folder. Full access is there. And no issue in restoring packages from nuget.org directly for other packages which are added.

From where can i see more logs related to this? If anyone else has faced same issue with it then please share your solution.



Solution 1:[1]

I guess this issue is more related to local folders instead of that central nuget repository cause you can access the packages there. And the Access to the path '..\packages\Microsoft.Owin.Security.Jwt\4.0.0' is denied. indicated something happened with the local folder.

..\packages\Microsoft.Owin.Security.Jwt\4.0.0

This path is quite strange. For packages.config format, the packages are store in C:\Users\xxx\.nuget\packages\Microsoft.Owin.Security.Jwt\4.0.0 or ..\packages\Microsoft.Owin.4.0.0\xxx(In solution folder). I'm not sure what's really happening to your project, here're some suggestions that may help:

1.Check the statements in your packages.config and xx.csproj, it should be:

<package id="Microsoft.Owin.Security.Jwt" version="4.0.0" targetFramework="netxxx" />

and

    <Reference Include="Microsoft.Owin.Security.Jwt, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
      <HintPath>..\packages\Microsoft.Owin.Security.Jwt.4.0.0\lib\net45\Microsoft.Owin.Security.Jwt.dll</HintPath>
      <Private>True</Private>
    </Reference>

If there exists any msbuild Target like this, delete it.

2.Close VS instance, delete the packages folder in Solution directory,and delete the packages folder in C:\Users\xxx\.nuget\packages.

3.Make sure https://api.nuget.org/v3/index.json is set as Package Sources.

After that, right-click solution=>Restore nuget packages to check if the issue goes away.(Enable these two options) Also, you can create a new empty project to consume the nuget package to check if it makes some difference. Hope it helps:)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1