NuGet 错误 NU1302
使用“HTTP”源运行“还原”操作:myHttpSource。 NuGet 需要 HTTPS 源。 若要使用 HTTP 源,必须在 NuGet.Config 文件中显式将“allowInsecureConnections”设置为 true。 有关详细信息,请参阅 https://aka.ms/nuget-https-everywhere。
问题
myHttpSource
是不安全的 HTTP 源。 建议改用 HTTPS 源。
溶液
选项 1:将源更新为使用 HTTPS
如果可能,请更新包源以使用 https://
而不是 http://
:
<configuration>
<packageSources>
<add key="SecureSource" value="https://example.com/nuget/" />
</packageSources>
</configuration>
选项 2:允许不安全的连接(如有必要)
如果源必须保持 HTTP,则通过在 NuGet.Config
中添加 AllowInsecureConnections
标志来显式允许不安全的连接:
<configuration>
<packageSources>
<add key="InsecureSource" value="http://example.com/nuget/" allowInsecureConnections="true" />
</packageSources>
</configuration>
选项 3:咨询 SDK 分析级别
项目中 SdkAnalysisLevel
属性可用作管理 HTTP 源的临时解决方法。
如果需要额外的时间来解决 HTTP 错误,可以降低 SdkAnalysisLevel
以暂时抑制错误。
下面是其工作原理:
- 对于 SDK 分析级别值 低于 9.0.100,使用 HTTP 源触发警告(NU1803)。
- 从 SDK 分析级别 9.0.100 或更高版本开始,除非显式启用
AllowInsecureConnections
,否则 HTTP 源将导致错误(NU1302)。