【问题标题】:Conflict of versions after upgrading to .NET 6 with ServiceCollection使用 ServiceCollection 升级到 .NET 6 后的版本冲突
【发布时间】:2021-11-09 14:56:43
【问题描述】:

事实证明,从 .NET 5 升级到 .NET 6 并不像我预期的那么简单。

由于以下错误,我所有的单元测试项目都无法编译

Severity    Code    Description Project File    Line    Suppression State
Error   CS0433  The type 'ServiceCollection' exists in both 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' and 'Microsoft.Extensions.DependencyInjection, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'    Sample.DynamoDb.FunctionalTests C:\src\my-solution\test\Sample.DynamoDb.FunctionalTests\DependencyInjectionTests\GetServiceTests.cs 22  Active

它们引用依赖于Microsoft.Extensions.DependencyInjection.Abstractions 版本 6 的类库 但由于某种原因,测试项目本身似乎依赖于Microsoft.Extensions.DependencyInjection。可能是被我使用的一些包拖过去了(我不知道是哪一个)。

这是我的测试项目

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

    <PropertyGroup>
        <TargetFramework>net6.0</TargetFramework>
        <Nullable>Enable</Nullable>
        <IsPackable>False</IsPackable>
        <IsPublishable>False</IsPublishable>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="FluentAssertions" Version="6.2.0" />
        <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />

        <PackageReference Include="xunit" Version="2.4.1" />
        <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
            <PrivateAssets>all</PrivateAssets>
        </PackageReference>
        <PackageReference Include="coverlet.collector" Version="3.1.0">
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
            <PrivateAssets>all</PrivateAssets>
        </PackageReference>
    </ItemGroup>

    <ItemGroup>
      <ProjectReference Include="..\..\src\Sample.DynamoDb.DependencyInjection\Sample.DynamoDb.DependencyInjection.csproj" />
    </ItemGroup>

</Project>

任何有类似问题的人或对如何排除故障和找到问题或解决方法有想法的人?

【问题讨论】:

  • csprojSample.DynamoDb.DependencyInjection?
  • 解决了,看我的回答。感谢您的宝贵时间!
  • 我们应该猜到 - 你没有升级Sample.DynamoDb.DependencyInjection.csproj 中的软件包吗?还是测试项目?
  • 我确实升级了所有软件包,但结果发现某些第三方依赖项依赖于 microsoft logging 5.0.0。现在已经解决了。谢谢!
  • 请不要在回答帖子中回答问题。我已经回滚了这些编辑。使用看起来你现在已经完成的答案帖子。

标签: .net-assembly .net-6.0


【解决方案1】:

原来问题是因为一些引用的项目,引用了另一个,引用了另一个...具有 nuget 依赖项 EventStore.Client.Grpc,它本身依赖于 Microsoft.Extensions.Logging 5.0.0

还有Microsoft.Extensions.Logging带来子依赖Microsoft.Extensions.DependencyInjection 5.0.0

查看我的测试项目的obj/project.assets.json 帮助我追踪到了这一点。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-04
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-13
    相关资源
    最近更新 更多