如何解决 NuGet "The package integrity check failed"错误?



我的开发环境如下:

  • Windows 10 Enterprise 64位
  • Visual Studio 2022专业版
  • .NET 6.0

我是使用NuGet的新手。我有持续的问题,NuGet无法安装带有错误"的软件包;包完整性检查失败">

这些步骤将在我的系统上一致地再现错误:

  1. 启动VS,选择";创建一个新项目">
  2. 筛选C#/Windows/Console并选择Console应用程序(而不是.NET Framework应用程序)
  3. Framework:.NET 6(长期支持)
  4. 一旦VS完成创建项目,右键单击解决方案资源管理器中的项目并选择";管理NuGet包">
  5. 单击浏览,输入"microsoft.data.sqlclient";在搜索框中,然后选择Microsoft.Data.SqlClient项。截至今天,最新的稳定版本是4.1.0。单击"安装"。我的包裹来源是";https://api.nuget.org/v3/index.json"如果这很重要
  6. 许多NuGet消息显示在Output窗口中,总是以NU3008错误结束。很抱歉,我不确定其中有多重要:
Restoring packages for d:devCoreConsoleTestCoreConsoleTest.csproj...
GET https://api.nuget.org/v3-flatcontainer/microsoft.data.sqlclient/index.json
OK https://api.nuget.org/v3-flatcontainer/microsoft.data.sqlclient/index.json 122ms
GET https://api.nuget.org/v3-flatcontainer/microsoft.data.sqlclient/4.1.0/microsoft.data.sqlclient.4.1.0.nupkg
OK https://api.nuget.org/v3-flatcontainer/microsoft.data.sqlclient/4.1.0/microsoft.data.sqlclient.4.1.0.nupkg 742ms
GET https://api.nuget.org/v3-flatcontainer/azure.core/index.json
GET https://api.nuget.org/v3-flatcontainer/microsoft.identity.client.extensions.msal/index.json
GET https://api.nuget.org/v3-flatcontainer/system.memory/index.json
GET https://api.nuget.org/v3-flatcontainer/system.text.json/index.json
GET https://api.nuget.org/v3-flatcontainer/microsoft.identity.client/index.json
GET https://api.nuget.org/v3-flatcontainer/microsoft.identitymodel.jsonwebtokens/index.json
GET https://api.nuget.org/v3-flatcontainer/microsoft.win32.registry/index.json
GET https://api.nuget.org/v3-flatcontainer/system.buffers/index.json
GET https://api.nuget.org/v3-flatcontainer/system.configuration.configurationmanager/index.json
GET https://api.nuget.org/v3-flatcontainer/system.diagnostics.diagnosticsource/index.json
GET https://api.nuget.org/v3-flatcontainer/system.runtime.caching/index.json
GET https://api.nuget.org/v3-flatcontainer/system.text.encoding.codepages/index.json
GET https://api.nuget.org/v3-flatcontainer/system.text.encodings.web/index.json
GET https://api.nuget.org/v3-flatcontainer/system.security.cryptography.cng/index.json
GET https://api.nuget.org/v3-flatcontainer/system.security.principal.windows/index.json
OK https://api.nuget.org/v3-flatcontainer/azure.core/index.json 46ms
GET https://api.nuget.org/v3-flatcontainer/azure.core/1.6.0/azure.core.1.6.0.nupkg
OK https://api.nuget.org/v3-flatcontainer/microsoft.identity.client.extensions.msal/index.json 123ms
OK https://api.nuget.org/v3-flatcontainer/system.text.json/index.json 133ms
GET https://api.nuget.org/v3-flatcontainer/microsoft.identity.client.extensions.msal/2.16.5/microsoft.identity.client.extensions.msal.2.16.5.nupkg
GET https://api.nuget.org/v3-flatcontainer/system.text.json/4.6.0/system.text.json.4.6.0.nupkg
OK https://api.nuget.org/v3-flatcontainer/system.memory/index.json 173ms
GET https://api.nuget.org/v3-flatcontainer/system.memory/4.5.3/system.memory.4.5.3.nupkg
OK https://api.nuget.org/v3-flatcontainer/microsoft.identity.client/index.json 190ms
GET https://api.nuget.org/v3-flatcontainer/microsoft.identity.client/4.22.0/microsoft.identity.client.4.22.0.nupkg
OK https://api.nuget.org/v3-flatcontainer/microsoft.win32.registry/index.json 208ms
GET https://api.nuget.org/v3-flatcontainer/microsoft.win32.registry/5.0.0/microsoft.win32.registry.5.0.0.nupkg
OK https://api.nuget.org/v3-flatcontainer/microsoft.identitymodel.jsonwebtokens/index.json 226ms
GET https://api.nuget.org/v3-flatcontainer/microsoft.identitymodel.jsonwebtokens/6.8.0/microsoft.identitymodel.jsonwebtokens.6.8.0.nupkg
OK https://api.nuget.org/v3-flatcontainer/system.buffers/index.json 246ms
GET https://api.nuget.org/v3-flatcontainer/system.buffers/4.5.1/system.buffers.4.5.1.nupkg
OK https://api.nuget.org/v3-flatcontainer/system.diagnostics.diagnosticsource/index.json 271ms
GET https://api.nuget.org/v3-flatcontainer/system.diagnostics.diagnosticsource/5.0.0/system.diagnostics.diagnosticsource.5.0.0.nupkg
OK https://api.nuget.org/v3-flatcontainer/system.text.encoding.codepages/index.json 294ms
OK https://api.nuget.org/v3-flatcontainer/system.configuration.configurationmanager/index.json 310ms
GET https://api.nuget.org/v3-flatcontainer/system.text.encoding.codepages/5.0.0/system.text.encoding.codepages.5.0.0.nupkg
GET https://api.nuget.org/v3-flatcontainer/system.configuration.configurationmanager/5.0.0/system.configuration.configurationmanager.5.0.0.nupkg
OK https://api.nuget.org/v3-flatcontainer/system.security.cryptography.cng/index.json 319ms
OK https://api.nuget.org/v3-flatcontainer/system.runtime.caching/index.json 327ms
GET https://api.nuget.org/v3-flatcontainer/system.security.cryptography.cng/5.0.0/system.security.cryptography.cng.5.0.0.nupkg
GET https://api.nuget.org/v3-flatcontainer/system.runtime.caching/5.0.0/system.runtime.caching.5.0.0.nupkg
OK https://api.nuget.org/v3-flatcontainer/system.text.encodings.web/index.json 357ms
GET https://api.nuget.org/v3-flatcontainer/system.text.encodings.web/4.7.2/system.text.encodings.web.4.7.2.nupkg
OK https://api.nuget.org/v3-flatcontainer/system.security.principal.windows/index.json 381ms
GET https://api.nuget.org/v3-flatcontainer/system.security.principal.windows/5.0.0/system.security.principal.windows.5.0.0.nupkg
OK https://api.nuget.org/v3-flatcontainer/system.memory/4.5.3/system.memory.4.5.3.nupkg 282ms
OK https://api.nuget.org/v3-flatcontainer/microsoft.identity.client/4.22.0/microsoft.identity.client.4.22.0.nupkg 392ms
OK https://api.nuget.org/v3-flatcontainer/azure.core/1.6.0/azure.core.1.6.0.nupkg 790ms
OK https://api.nuget.org/v3-flatcontainer/microsoft.identity.client.extensions.msal/2.16.5/microsoft.identity.client.extensions.msal.2.16.5.nupkg 721ms
OK https://api.nuget.org/v3-flatcontainer/system.text.json/4.6.0/system.text.json.4.6.0.nupkg 713ms
OK https://api.nuget.org/v3-flatcontainer/microsoft.identitymodel.jsonwebtokens/6.8.0/microsoft.identitymodel.jsonwebtokens.6.8.0.nupkg 621ms
OK https://api.nuget.org/v3-flatcontainer/system.buffers/4.5.1/system.buffers.4.5.1.nupkg 601ms
OK https://api.nuget.org/v3-flatcontainer/system.diagnostics.diagnosticsource/5.0.0/system.diagnostics.diagnosticsource.5.0.0.nupkg 713ms
OK https://api.nuget.org/v3-flatcontainer/system.configuration.configurationmanager/5.0.0/system.configuration.configurationmanager.5.0.0.nupkg 684ms
OK https://api.nuget.org/v3-flatcontainer/system.runtime.caching/5.0.0/system.runtime.caching.5.0.0.nupkg 888ms
OK https://api.nuget.org/v3-flatcontainer/microsoft.win32.registry/5.0.0/microsoft.win32.registry.5.0.0.nupkg 3605ms
OK https://api.nuget.org/v3-flatcontainer/system.text.encoding.codepages/5.0.0/system.text.encoding.codepages.5.0.0.nupkg 3521ms
OK https://api.nuget.org/v3-flatcontainer/system.security.cryptography.cng/5.0.0/system.security.cryptography.cng.5.0.0.nupkg 4748ms
OK https://api.nuget.org/v3-flatcontainer/system.text.encodings.web/4.7.2/system.text.encodings.web.4.7.2.nupkg 5143ms
OK https://api.nuget.org/v3-flatcontainer/system.security.principal.windows/5.0.0/system.security.principal.windows.5.0.0.nupkg 5121ms
Installed Microsoft.IdentityModel.JsonWebTokens 6.8.0 from https://api.nuget.org/v3/index.json with content hash +7JIww64PkMt7NWFxoe4Y/joeF7TAtA/fQ0b2GFGcagzB59sKkTt/sMZWR6aSZht5YC7SdHi3W6yM1yylRGJCQ==.
Installed Microsoft.Identity.Client.Extensions.Msal 2.16.5 from https://api.nuget.org/v3/index.json with content hash VlGUZEpF8KP/GCfFI59sdE0WA0o9quqwM1YQY0dSp6jpGy5EOBkureaybLfpwCuYUUjQbLkN2p7neUIcQCfbzA==.
Installed Azure.Core 1.6.0 from https://api.nuget.org/v3/index.json with content hash kI4m2NsODPOrxo0OoKjk6B3ADbdovhDQIEmI4039upjjZKRaewVLx/Uz4DfRa/NtnIRZQPUALe1yvdHWAoRt4w==.
Installed System.Memory 4.5.3 from https://api.nuget.org/v3/index.json with content hash 3oDzvc/zzetpTKWMShs1AADwZjQ/36HnsufHRPcOjyRAAMLDlu2iD33MBI2opxnezcVUtXyqDXXjoFMOU9c7SA==.
Package 'System.Text.Encoding.CodePages 5.0.0' from source 'https://api.nuget.org/v3/index.json': Signature Hash Algorithm: SHA256
Package 'System.Text.Encoding.CodePages 5.0.0' from source 'https://api.nuget.org/v3/index.json': Verifying the author primary signature with certificate: 
Package 'System.Text.Encoding.CodePages 5.0.0' from source 'https://api.nuget.org/v3/index.json':   SHA1 hash: F404000FB11E61F446529981C7059A76C061631E
Package 'System.Text.Encoding.CodePages 5.0.0' from source 'https://api.nuget.org/v3/index.json':   Issued by: CN=DigiCert SHA2 Assured ID Code Signing CA, OU=www.digicert.com, O=DigiCert Inc, C=US
Package 'System.Text.Encoding.CodePages 5.0.0' from source 'https://api.nuget.org/v3/index.json': Timestamp: 10/20/2020 9:29:58 AM
Package 'System.Text.Encoding.CodePages 5.0.0' from source 'https://api.nuget.org/v3/index.json': Verifying author primary signature's timestamp with timestamping service certificate: 
Subject Name: CN=Symantec SHA256 TimeStamping Signer - G3, OU=Symantec Trust Network, O=Symantec Corporation, C=US
SHA1 hash: A9A4121063D71D48E8529A4681DE803E3E7954B0
SHA256 hash: C474CE76007D02394E0DA5E4DE7C14C680F9E282013CFEF653EF5DB71FDF61F8
Issued by: CN=Symantec SHA256 TimeStamping CA, OU=Symantec Trust Network, O=Symantec Corporation, C=US
Valid from: 12/22/2017 7:00:00 PM to 3/22/2029 7:59:59 PM
Installed System.Text.Json 4.6.0 from https://api.nuget.org/v3/index.json with content hash 4F8Xe+JIkVoDJ8hDAZ7HqLkjctN/6WItJIzQaifBwClC7wmoLSda/Sv2i6i1kycqDb3hWF4JCVbpAweyOKHEUA==.
Installed System.Runtime.Caching 5.0.0 from https://api.nuget.org/v3/index.json with content hash 30D6MkO8WF9jVGWZIP0hmCN8l9BTY4LCsAzLIe4xFSXzs+AjDotR7DpSmj27pFskDURzUvqYYY0ikModgBTxWw==.
Installed System.Text.Encodings.Web 4.7.2 from https://api.nuget.org/v3/index.json with content hash iTUgB/WtrZ1sWZs84F2hwyQhiRH6QNjQv2DkwrH+WP6RoFga2Q1m3f9/Q7FG8cck8AdHitQkmkXSY8qylcDmuA==.
Installed System.Buffers 4.5.1 from https://api.nuget.org/v3/index.json with content hash Rw7ijyl1qqRS0YQD/WycNst8hUUMgrMH4FCn1nNm27M4VxchZ1js3fVjQaANHO5f3sN4isvP4a+Met9Y4YomAg==.
Installed System.Configuration.ConfigurationManager 5.0.0 from https://api.nuget.org/v3/index.json with content hash aM7cbfEfVNlEEOj3DsZP+2g9NRwbkyiAv2isQEzw7pnkDg9ekCU2m1cdJLM02Uq691OaCS91tooaxcEn8d0q5w==.
Installed System.Diagnostics.DiagnosticSource 5.0.0 from https://api.nuget.org/v3/index.json with content hash tCQTzPsGZh/A9LhhA6zrqCRV4hOHsK90/G7q3Khxmn6tnB1PuNU0cRaKANP2AWcF9bn0zsuOoZOSrHuJk6oNBA==.
Package 'Microsoft.Identity.Client 4.22.0' from source 'https://api.nuget.org/v3/index.json': Signature Hash Algorithm: SHA256
Package 'Microsoft.Identity.Client 4.22.0' from source 'https://api.nuget.org/v3/index.json': Verifying the author primary signature with certificate: 
Package 'Microsoft.Identity.Client 4.22.0' from source 'https://api.nuget.org/v3/index.json':   SHA1 hash: F404000FB11E61F446529981C7059A76C061631E
Package 'Microsoft.Identity.Client 4.22.0' from source 'https://api.nuget.org/v3/index.json':   Issued by: CN=DigiCert SHA2 Assured ID Code Signing CA, OU=www.digicert.com, O=DigiCert Inc, C=US
Package 'Microsoft.Identity.Client 4.22.0' from source 'https://api.nuget.org/v3/index.json': Timestamp: 10/22/2020 1:50:36 PM
Package 'Microsoft.Identity.Client 4.22.0' from source 'https://api.nuget.org/v3/index.json': Verifying author primary signature's timestamp with timestamping service certificate: 
Subject Name: CN=Symantec SHA256 TimeStamping Signer - G3, OU=Symantec Trust Network, O=Symantec Corporation, C=US
SHA1 hash: A9A4121063D71D48E8529A4681DE803E3E7954B0
SHA256 hash: C474CE76007D02394E0DA5E4DE7C14C680F9E282013CFEF653EF5DB71FDF61F8
Issued by: CN=Symantec SHA256 TimeStamping CA, OU=Symantec Trust Network, O=Symantec Corporation, C=US
Valid from: 12/22/2017 7:00:00 PM to 3/22/2029 7:59:59 PM
Installed Microsoft.Win32.Registry 5.0.0 from https://api.nuget.org/v3/index.json with content hash dDoKi0PnDz31yAyETfRntsLArTlVAVzUzCIvvEDsDsucrl33Dl8pIJG06ePTJTI3tGpeyHS9Cq7Foc/s4EeKcg==.
Package 'Microsoft.Data.SqlClient 4.1.0' from source 'https://api.nuget.org/v3/index.json': Signature Hash Algorithm: SHA256
Package 'Microsoft.Data.SqlClient 4.1.0' from source 'https://api.nuget.org/v3/index.json': Verifying the author primary signature with certificate: 
Package 'Microsoft.Data.SqlClient 4.1.0' from source 'https://api.nuget.org/v3/index.json':   SHA1 hash: A6E18D21B507879FC7F9C392A5CE355936E3AD2C
Package 'Microsoft.Data.SqlClient 4.1.0' from source 'https://api.nuget.org/v3/index.json':   Issued by: CN=DigiCert SHA2 Assured ID Code Signing CA, OU=www.digicert.com, O=DigiCert Inc, C=US
Package 'Microsoft.Data.SqlClient 4.1.0' from source 'https://api.nuget.org/v3/index.json': Timestamp: 1/31/2022 5:36:44 PM
Package 'Microsoft.Data.SqlClient 4.1.0' from source 'https://api.nuget.org/v3/index.json': Verifying author primary signature's timestamp with timestamping service certificate: 
Subject Name: CN=Symantec SHA256 TimeStamping Signer - G3, OU=Symantec Trust Network, O=Symantec Corporation, C=US
SHA1 hash: A9A4121063D71D48E8529A4681DE803E3E7954B0
SHA256 hash: C474CE76007D02394E0DA5E4DE7C14C680F9E282013CFEF653EF5DB71FDF61F8
Issued by: CN=Symantec SHA256 TimeStamping CA, OU=Symantec Trust Network, O=Symantec Corporation, C=US
Valid from: 12/22/2017 7:00:00 PM to 3/22/2029 7:59:59 PM
Installed System.Security.Principal.Windows 5.0.0 from https://api.nuget.org/v3/index.json with content hash t0MGLukB5WAVU9bO3MGzvlGnyJPgUlcwerXn1kzBRjwLKixT96XV0Uza41W49gVd8zEMFu9vQEFlv0IOrytICA==.
Installed System.Security.Cryptography.Cng 5.0.0 from https://api.nuget.org/v3/index.json with content hash jIMXsKn94T9JY7PvPq/tMfqa6GAaHpElRDpmG+SuL+D3+sTw2M8VhnibKnN8Tq+4JqbPJ/f+BwtLeDMEnzAvRg==.
NU3008: Package 'System.Text.Encoding.CodePages 5.0.0' from source 'https://api.nuget.org/v3/index.json': The package integrity check failed. The package has changed since it was signed. Try clearing the local http-cache and run nuget operation again.
NU3008: Package 'Microsoft.Identity.Client 4.22.0' from source 'https://api.nuget.org/v3/index.json': The package integrity check failed. The package has changed since it was signed. Try clearing the local http-cache and run nuget operation again.
NU3008: Package 'Microsoft.Data.SqlClient 4.1.0' from source 'https://api.nuget.org/v3/index.json': The package integrity check failed. The package has changed since it was signed. Try clearing the local http-cache and run nuget operation again.
Time Elapsed: 00:00:14.2400739

我尝试过的:

  • 重新启动
  • 清除我的本地缓存(我已经尝试过很多次了,都是从命令行的nuget程序和VS下的Tools、Options、nuget Package Manager、Clear All nuget cache)
  • 从NuGet单独安装依赖项
  • 修复Visual Studio 2022安装

我已经试着解决这个问题将近两天了,我开始看到红色的薄雾。我不明白为什么会失败,也不明白如何修复它,我对微软让以前简单的添加依赖关系的过程变得复杂和不透明感到非常沮丧。求你了,有什么帮助吗?

更新

需要澄清的是,这并不是每个包都会发生,但Microsoft.Data.SqlClient(和其他Microsoft包)每次都会发生。

我使用的是最新版本的nuget命令行工具(6.2.1.2)

除了卸载和重新安装Visual Studio之外,我已经尝试了徐静淼在下面提出的所有建议。建议#2,从另一台机器上复制失败的包,确实奏效了,但我不接受这是一个站得住脚的永久解决方案。每当我需要安装微软的软件包时,我是否应该纠缠同事?

我遇到了这个问题,它几乎和我的完全一样,包括包和包版本。不幸的是,它没有包含有关决议的详细信息。如果我们的公司网络有问题,我需要向他们详细说明。什么样的网络功能可能会干扰NuGet软件包的下载?

根据您的描述,错误消息显示"尝试清除本地http缓存并再次运行nuget操作"。此文档建议运行nuget locals http-cache -cleardotnet nuget locals http-cache --clear命令来清除本地http高速缓存。

如果它不起作用,你可以尝试以下方法:

  1. 关闭VS,从C:Usersxxx(current user)AppDataRoamingNuGet、中删除nuget.config文件

    删除解决方案文件夹的.vs隐藏文件夹,项目的binobj文件夹,

    然后重新启动VS以重新生成该文件以检查它是否工作。

  2. 将另一台工作电脑上的nuget包Microsoft.Data.SqlClient复制到%userprofile%.nugetpackages中。然后在那里重新安装你的nuget软件包,检查这是否有效。

  3. 从该链接下载最新的nuget.exe v6.2.1,然后关闭VS并重新启动您的项目,并在CMD:下运行此命令

    nuget restore

  4. 最后,您可以尝试卸载vs并重新安装。安装后,您可以检查问题是否存在。

最新更新