I am using VS 2017 version 15.9.38. I recently started getting an error when I build an old project. It’s a web project that has an Angular application. The error is:
Package Microsoft.AspNetCore.DataProtection, version 2.1.1 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.
This error is located in a file called: C:\Program Files\dotnet\sdk\2.1.526\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets on a line that says:
<ResolvePackageAssets
ProjectAssetsFile="$(ProjectAssetsFile)"
ProjectAssetsCacheFile="$(ProjectAssetsCacheFile)"
ProjectPath="$(MSBuildProjectFullPath)"
ProjectLanguage="$(Language)"
EmitAssetsLogMessages="$(EmitAssetsLogMessages)"
TargetFrameworkMoniker="$(NuGetTargetMoniker)"
RuntimeIdentifier="$(RuntimeIdentifier)"
MarkPackageReferencesAsExternallyResolved="$(MarkPackageReferencesAsExternallyResolved)"
DisablePackageAssetsCache="$(DisablePackageAssetsCache)"
DisableFrameworkAssemblies="$(DisableLockFileFrameworks)"
DisableTransitiveProjectReferences="$(DisableTransitiveProjectReferences)"
EnsureRuntimePackageDependencies="$(EnsureRuntimePackageDependencies)"
VerifyMatchingImplicitPackageVersion="$(VerifyMatchingImplicitPackageVersion)"
ExpectedPlatformPackages="@(ExpectedPlatformPackages)"
>
My project doesn’t have a packages.config file or a packages subfolder like some of my projects.
In my project csproj file, there’s a section that says:
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="2.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.1" />
</ItemGroup>
Another way I can see there’s an error is in the Solution Explorer, under the Dependencies/Nuget node, all the packages have a yellow triangle with an exclamation point. Here are all the things I have tried:
In VS Options, for Nuget, these are checked (I also tried unchecking them for good measure):
- Allow Nuget to download missing packages
- Automatically check for missing packages during build
Clear Nuget cache
Clean and rebuild project
Restarting VS
Rebooting computer
Deleting this folder: c:\users\my_username.nuget
I try updating some of the packages to a newer version using the Nuget Package Manager, and I get this error:
C:\Program Files\dotnet\sdk\2.1.526\NuGet.targets(114,5): error : An error occurred while retrieving package metadata for 'System.IO.Compression.ZipFile.4.3.0' from source 'C:\Program Files\dotnet\sdk\NuGetFallbackFolder'. C:\Program Files\dotnet\sdk\2.1.526\NuGet.targets(114,5): error : Nuspec file does not exist in package.
I will refer to this new error as ERROR B.
I try removing all the packages and then installing them afresh with the Nuget Package Manager, and I get ERROR B.
I opened the nuget package mgr console in VS and ran this:
Update-Package -Reinstall
And got this response:
No package updates are available from the current package source for project 'whatever'.
I ran this in the console and got ERROR B:
Update-Package
I opened a command prompt (not in VS) and tried to run a few things. But whenever I run them, I get ERROR B. These are things I tried:
dotnet restore --force-evaluate
dotnet restore
dotnet build
dotnet nuget locals --clear all
I tried reinstalling the SDK 2.1.526, and that didn’t help.
I have seen some people suggest you can reinstall or update Nuget, but I can’t figure out how to do this. For example, when I follow these steps, Nuget and Package Manager aren’t available. I looked for them in the extensions to uninstall, but they aren’t there.
- In Visual Studio, from the "Tools" menu choose the "Extensions and Updates" option.
- From the dialog that appears, expand the "Updates" node from the tree at the left side.
- Select the "Visual Studio Gallery" option from the tree.
- Finally, look for the Package Manager update in the list of updates at the right side of the dialog and click the "Update" button beside it.
I tried downloading the CLI nuget.exe and running this, but still got ERROR B:
nuget restore whatever.sln
I tried running all these commands in a command line window with administrator permissions, and it doesn’t help.
Is there anything else I can try? thanks in advance
CodePudding user response:
Focusing on what you call "error B":
C:\Program Files\dotnet\sdk\2.1.526\NuGet.targets(114,5): error : An error occurred while retrieving package metadata for 'System.IO.Compression.ZipFile.4.3.0' from source 'C:\Program Files\dotnet\sdk\NuGetFallbackFolder'. C:\Program Files\dotnet\sdk\2.1.526\NuGet.targets(114,5): error : Nuspec file does not exist in package
Is there actually a .nuspec
file in your C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.io.compression.zipfile\4.3.0
folder?
I have one and its contents are valid XML:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="2.12">
<id>System.IO.Compression.ZipFile</id>
<version>4.3.0</version>
<title>System.IO.Compression.ZipFile</title>
<authors>Microsoft</authors>
<owners>microsoft,dotnetframework</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<licenseUrl>http://go.microsoft.com/fwlink/?LinkId=329770</licenseUrl>
<projectUrl>https://dot.net/</projectUrl>
<iconUrl>http://go.microsoft.com/fwlink/?LinkID=288859</iconUrl>
<description>Provides classes that support the compression and decompression of streams using file system paths.
Commonly Used Types:
System.IO.Compression.ZipFile
When using NuGet 3.x this package requires at least version 3.4.</description>
<releaseNotes>https://go.microsoft.com/fwlink/?LinkID=799421</releaseNotes>
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
<serviceable>true</serviceable>
<dependencies>
<group targetFramework="MonoAndroid1.0" />
<group targetFramework="MonoTouch1.0" />
<group targetFramework=".NETFramework4.6" />
<group targetFramework=".NETStandard1.3">
<dependency id="System.Buffers" version="4.3.0" exclude="Compile" />
<dependency id="System.IO" version="4.3.0" exclude="Compile" />
<dependency id="System.IO.Compression" version="4.3.0" />
<dependency id="System.IO.FileSystem" version="4.3.0" exclude="Compile" />
<dependency id="System.IO.FileSystem.Primitives" version="4.3.0" exclude="Compile" />
<dependency id="System.Resources.ResourceManager" version="4.3.0" exclude="Compile" />
<dependency id="System.Runtime" version="4.3.0" />
<dependency id="System.Runtime.Extensions" version="4.3.0" exclude="Compile" />
<dependency id="System.Text.Encoding" version="4.3.0" />
</group>
<group targetFramework="Xamarin.iOS1.0" />
<group targetFramework="Xamarin.Mac2.0" />
<group targetFramework="Xamarin.TVOS1.0" />
<group targetFramework="Xamarin.WatchOS1.0" />
</dependencies>
<frameworkAssemblies>
<frameworkAssembly assemblyName="mscorlib" targetFramework=".NETFramework4.6" />
<frameworkAssembly assemblyName="System.IO.Compression.FileSystem" targetFramework=".NETFramework4.6" />
</frameworkAssemblies>
</metadata>
</package>
If that file is missing or corrupted, it would explain the issues you're seeing. You might try renaming the System.IO.Compression.ZipFile
folder and trying to restore your project again.
Can you also try this command:
nuget.exe locals all -clear