Visual Studio CSPROJ 与解决方案资源管理器的版本不一致

问题描述 投票:0回答:1

在我的 C# Visual Studio 项目中,我打开 Package Manager Console 并输入:

dotnet add package Microsoft.Extensions.Configuration.Binder

它给我的输出是:

Each package is licensed to you by its owner. NuGet is not responsible for, nor does it grant any licenses to, third-party packages. Some packages may include dependencies which are governed by additional licenses. Follow the package source (feed) URL to determine any dependencies.

Package Manager Console Host Version 6.7.0.127

Type 'get-help NuGet' to see all available NuGet commands.

PM> dotnet add package Microsoft.Extensions.Configuration.Binder
  Determining projects to restore...
  Writing C:\Users\myuser\AppData\Local\Temp\2\tmp7BD5.tmp
info : X.509 certificate chain validation will use the default trust store selected by .NET for code signing.
info : X.509 certificate chain validation will use the default trust store selected by .NET for timestamping.
info : Adding PackageReference for package 'Microsoft.Extensions.Configuration.Binder' into project 'C:\Users\myuser\repos\Data%20Platform\edi-parser\InterestRecoveryEdiParser\InterestRecoveryEdiParser.csproj'.
info :   CACHE https://api.nuget.org/v3/registration5-gz-semver2/microsoft.extensions.configuration.binder/index.json
info : Restoring packages for C:\Users\myuser\repos\Data%20Platform\edi-parser\InterestRecoveryEdiParser\InterestRecoveryEdiParser.csproj...
info : Package 'Microsoft.Extensions.Configuration.Binder' is compatible with all the specified frameworks in project 'C:\Users\myuser\repos\Data%20Platform\edi-parser\InterestRecoveryEdiParser\InterestRecoveryEdiParser.csproj'.
info : PackageReference for package 'Microsoft.Extensions.Configuration.Binder' version '8.0.0' added to file 'C:\Users\myuser\repos\Data%20Platform\edi-parser\InterestRecoveryEdiParser\InterestRecoveryEdiParser.csproj'.
info : Generating MSBuild file C:\Users\myuser\repos\Data%20Platform\edi-parser\InterestRecoveryEdiParser\obj\InterestRecoveryEdiParser.csproj.nuget.g.targets.
info : Writing assets file to disk. Path: C:\Users\myuser\repos\Data%20Platform\edi-parser\InterestRecoveryEdiParser\obj\project.assets.json
log  : Restored C:\Users\myuser\repos\Data%20Platform\edi-parser\InterestRecoveryEdiParser\InterestRecoveryEdiParser.csproj (in 107 ms).
PM>

在我的 CSPROJ XML 文件中:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="Config.cs" />
    <Compile Include="Program.cs" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
    <PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
    <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
    <PackageReference Include="Microsoft.Extensions.Options" Version="8.0.0" />
  </ItemGroup>

</Project>

所以看起来它安装了版本 8.0.0(以及其他

Microsoft.Extensions
软件包的 8.0.0 版本)。 但后来在我的解决方案资源管理器中我看到:

当我展开该错误时,它告诉我:

Warning As Error: Detected package downgrade: Microsoft.Extensions.Configuration.Binder from 8.0.0 to 5.0.0. Reference the package directly from the project to select a different version. 
 InterestRecoveryEdiParser -> Microsoft.Extensions.Logging.Console 8.0.0 -> Microsoft.Extensions.Logging.Configuration 8.0.0 -> Microsoft.Extensions.Configuration.Binder (>= 8.0.0) 
 InterestRecoveryEdiParser -> Microsoft.Extensions.Configuration.Binder (>= 5.0.0)

这是怎么回事?就好像我的项目一半正在尝试使用 8.0.0,另一半正在使用 5.0.0。

当我尝试运行我的项目时,它告诉我存在构建错误,然后引用相同的错误。如何删除 5.0.0 依赖并替换为 8.0.0 版本?

c# .net visual-studio nuget
1个回答
0
投票

您可以尝试右键单击“解决方案资源管理器”中的项目,然后单击“管理器 NuGet 包”以打开 NuGet 包管理器 enter image description here

找到旧版本的 Nuget 包并将其更新到您需要的版本。

© www.soinside.com 2019 - 2024. All rights reserved.