I was upgrading the solution from .Net core  3.1 to .NET 6.0 and got the below error while building the project.

Package StyleCop.Analyzers, version 1.0.2 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions.

Error Image

Then I tried to clean and build the solution again, but the error didn’t disappear. So later, I found the solution to this.

Solution 1

  1. Launch Group Policy Editor. Run “gpedit.msc” from the Rum command (Windows-R and then type “gpedit.msc” and click on). Alternatively in Start search bar search “Edit group policy” and open Group Policy Editor.
  2. Go to Local Group Policy Editor as illustrated below, Select enable “Local Computer Policy” à Administrative templatesàAll Settingsà Enable Win32 long paths.

Click Enable, Apply, and then click Ok as depicted below.

Note that, this is supported in Windows 10 and Windows Server 2016.

Restart the visual studio and try building the solution.

Solution 2

Run the below command

dotnet restore

If you are still getting the error then try running the below cmd.

 MSBuild /t:restore

You can follow the below links for details.

Microsoft docs

Leave a Reply

Your email address will not be published. Required fields are marked *