I was upgrading the solution from .Net core  3.1 to .NET 6.0 and got the below error while building the project. This blog describes how I resolved the error and different ways to resolve the issue after upgrading to .NET 6.0.

Error message:

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–>policy setting.

Then, 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

or

msbuild -t:build -restore

You can follow the below links for more details.

Microsoft docs

I hope, it will be helpful, if you encounter a similar kind of problem while upgrading your solution to the upper version of .NET.

Leave a Reply

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