Martin Graupner
Martin Graupner

Reputation: 133

Restore NuGet packages failed for project ... : Could not find a part of the path

I'm trying to run a Unit Test project in Visual Studio (.NET Framework 4.72).

The project is now building/running successfully, however there is still an error that the NuGet packages can't be restored (the file path is actually wrong and does not exist.). How can I change to the right file path and tell VS to not look in the wrong path? Here's the error:

NuGet Package restore failed for project Tests_WeatherData: Could not find a part of the path 'C:......\Begin\packages\MSTest.TestAdapter.1.3.2\build/_common/zh-Hans/Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.resources.dll'

Thank you for any advice how to change the file path/restoring settings.

Upvotes: 9

Views: 35438

Answers (5)

gadildafissh
gadildafissh

Reputation: 2402

Another option to fixing the long path issue is to do it from the Powershell with Admin privileges. (right-click and choose "Run as Administrator").

  1. Close Visual Studio

  2. Paste the following into Powershell:

    New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD ` -Force

  3. Add the NuGet package via the Powersell by navigating to your project's directory and running this command:

    dotnet add package

Upvotes: 1

Protector one
Protector one

Reputation: 7261

After I updated a Nuget package, Visual Studio included newly added folders for both the old and the updated version in my list of Pending Changes. The old version obviously no longer existed, since it was deleted when Nuget updated the package. I had to manually exclude the folder named with the old version number.

Upvotes: -1

Amogh Natu
Amogh Natu

Reputation: 881

This is what worked for me.

  1. Download nuget.exe from here. Screenshot of link where nuget.exe can be downloaded, with an arrow pointing to the location of the download link on the page.

  2. Copy this nuget.exe executable to the folder that contains the solution which is currently failing to build.

  3. Ensure that the LongPathsEnabled registry key is set to 1.

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled

  4. Open cmd prompt, navigate to the above folder location. Run the below command.

    c:\repos\MySolutionFolder>nuget.exe restore

  5. Build the solution in Visual Studio. In my case I used VS2019.

Link that helped me with these steps - Github-Issue.

Upvotes: 14

Gary Barrett
Gary Barrett

Reputation: 2018

It can be caused by having your project located within a subfolder that is too deeply nested. I think possibly there's some limit for the folder path like maybe 250 characters or something like that.

I saw the same error when I downloaded a zip with some demo projects and when I unzipped it created a folder with many subfolders. The project I was interested in was down pretty deep in the subfolders and when I tried to restore its NuGet packages I got the same errors.

I moved the project folder up nearer to c:\ and then the restore errors went away.

Upvotes: 22

HouseCat
HouseCat

Reputation: 1613

The issue could be filepaths in your CSPROJ file. Most common cause is project restructure and the location of packages has changed.

In addition to NUGET references in the CSPROJ, there could be a few other spots in the footer of the CSPROJ or the header portion for MSTest adapter entries. I.e. just verify all your filepaths (especially relative) ones are all correct and reload/rebuild.

Upvotes: 0

Related Questions