Visual Studio 无法降级NuGet软件包

mqxuamgl  于 2022-12-14  发布在  其他
关注(0)|答案(2)|浏览(222)

我有一个.NET 6项目,我想降级到.NET 5,所以我将目标框架从6更改为5。

<TargetFramework>net5.0</TargetFramework>

这样做之后,我得到了很多包兼容性错误,这是预期的,例如:

Package Microsoft.EntityFrameworkCore.Tools 6.0.5 is not compatible with net5.0 (.NETCoreApp,Version=v5.0). Package Microsoft.EntityFrameworkCore.Tools 6.0.5 supports: net6.0 (.NETCoreApp,Version=v6.0)

然而,当我尝试使用NuGet软件包管理器或软件包管理器控制台降级软件包时,我收到了所有其他软件包的兼容性错误,软件包降级失败。似乎我无法逐个降级每个软件包,不知何故,我需要同时降级所有软件包。
输入:

Install-Package Microsoft.EntityFrameworkCore.Tools -Version 5.0.17

输出量:

Install-Package : NU1202: Package Abp.AspNetCore.SignalR 7.2.1 is not compatible with net5.0 (.NETCoreApp,Version=v5.0). Package Abp.AspNetCore.SignalR 7.2.1 supports: net6.0 
(.NETCoreApp,Version=v6.0)
At line:1 char:1
+ Install-Package Microsoft.EntityFrameworkCore.Design -Version 5.0.17
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
 
Install-Package : NU1202: Package Microsoft.AspNetCore.Authentication.JwtBearer 6.0.5 is not compatible with net5.0 (.NETCoreApp,Version=v5.0). Package 
Microsoft.AspNetCore.Authentication.JwtBearer 6.0.5 supports: net6.0 (.NETCoreApp,Version=v6.0)
At line:1 char:1
+ Install-Package Microsoft.EntityFrameworkCore.Design -Version 5.0.17
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
 
Install-Package : NU1202: Package Microsoft.EntityFrameworkCore.SqlServer 6.0.5 is not compatible with net5.0 (.NETCoreApp,Version=v5.0). Package Microsoft.EntityFrameworkCore.SqlServer 6.0.5 
supports: net6.0 (.NETCoreApp,Version=v6.0)
At line:1 char:1
+ Install-Package Microsoft.EntityFrameworkCore.Design -Version 5.0.17
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
 
Install-Package : NU1202: Package Microsoft.EntityFrameworkCore 6.0.5 is not compatible with net5.0 (.NETCoreApp,Version=v5.0). Package Microsoft.EntityFrameworkCore 6.0.5 supports: net6.0 
(.NETCoreApp,Version=v6.0)
At line:1 char:1
+ Install-Package Microsoft.EntityFrameworkCore.Design -Version 5.0.17
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
 
Install-Package : NU1202: Package Owl.reCAPTCHA 0.5.0 is not compatible with net5.0 (.NETCoreApp,Version=v5.0). Package Owl.reCAPTCHA 0.5.0 supports: net6.0 (.NETCoreApp,Version=v6.0)
At line:1 char:1
+ Install-Package Microsoft.EntityFrameworkCore.Design -Version 5.0.17
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
 
Install-Package : Package restore failed. Rolling back package changes for 'ATC.Web.Host'.
At line:1 char:1
+ Install-Package Microsoft.EntityFrameworkCore.Design -Version 5.0.17
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
kknvjkwl

kknvjkwl1#

我在升级某些软件包时也遇到过类似的问题。我进入项目文件,手动编辑版本号。

jchrr9hc

jchrr9hc2#

你安装的nuget包之间有一个引用关系。所以当你使用命令行Install-Package Microsoft.EntityFrameworkCore.Tools -Version 5.0.17时会得到这些错误。
正如jmcilhinney所说,您可以在.proj文件中更改包的版本,但您必须确保修改后的版本号与.net5兼容,您可以在nuget.org中查看版本和适用的框架。
此问题的另一个解决方案是卸载所有软件包并重新安装.net5兼容版本。

相关问题