【问题标题】:.NET Core build warning due to different versions of EntityFramework由于 EntityFramework 版本不同而导致的 .NET Core 构建警告
【发布时间】:2020-11-23 14:05:40
【问题描述】:

使用 VS 2019,我的几个项目在编译时会生成此构建警告:

5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2081,5): 警告 MSB3277:发现不同版本的冲突 无法解决的“Microsoft.EntityFrameworkCore”。这些 当日志详细程度为 设置为详细。

由于日志不是真的...冗长(即使在详细模式下),我调查了一下,似乎该错误是由 Pomelo.EntityFrameworkCore.Mysql/3.1.2 引起的(我们使用的是 MariaDB)。这是一个项目 json 的摘录,它依赖于 EF 3.1.0,而当前版本是 3.1.6:

  "Pomelo.EntityFrameworkCore.MySql/3.1.2": {
    "type": "package",
    "dependencies": {
      "Microsoft.EntityFrameworkCore.Relational": "3.1.0",
      "MySqlConnector": "[0.61.0, 1.0.0)",
      "Pomelo.JsonObject": "2.2.1"
    },

以下是 PackageReference 的示例,其中包含发生警告的测试项目的部分:

  <ItemGroup>
    <PackageReference Include="FluentAssertions" Version="5.10.3" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
    <PackageReference Include="NSubstitute" Version="4.2.2" />
    <PackageReference Include="XmlUnit.Core" Version="2.8.0" />
    <PackageReference Include="xunit" Version="2.4.1" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.2">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="coverlet.collector" Version="1.3.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

我该怎么办:

  • 忽略此警告(并等待 pomelo 更新依赖项)
  • 降级到 EF 3.1.0
  • 还有其他想法吗?

BR

【问题讨论】:

  • AutoGenerateBindingRedirects and GenerateBindingRedirectsOutputType 添加到 csproj,这会导致使用 3.1.6
  • 不幸的是,这样做会增加一个额外的警告(并且不能解决现有的警告):严重性代码描述项目文件行抑制状态警告 MSB3277 发现不同版本的“System.Configuration.ConfigurationManager”之间的冲突可能不能解决。当日志详细程度设置为详细时,这些引用冲突会列在构建日志中。 EP2Converter.Tests C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets 2081
  • 发布您的 csprojs 的所有“PackageReference Include”条目
  • 刚刚添加到我的问题中
  • 将 Pomelo.EntityFrameworkCore.MySql 和 Microsoft.EntityFrameworkCore.Relational(以及 nuget.org/packages/System.Configuration.ConfigurationManager/…,如果您仍然收到消息)直接添加到测试项目中。

标签: entity-framework .net-core mariadb pomelo-entityframeworkcore-mysql


【解决方案1】:

测试项目缺少对问题包的引用。仅将它们添加到您在第二个项目中引用的项目中是不够的。

所以将它们添加到测试项目中:

<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.6" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.1.2" />

如果您仍然有与 System.Configuration.ConfigurationManager 相关的问题,请添加

<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" />

去测试csproj。

【讨论】:

  • 经验教训:您似乎必须在测试应用程序中包含相同的包;
  • 这个答案对我有用,但我有一个后续问题,为什么我需要这样做?即使我不添加两次引用,我也有其他项目可以顺利运行。理想情况下,我想避免这种情况,因为如果我在一个项目中升级包,那么我需要在另一个项目中升级包。
  • @shelbypereira 这个新的包引用包含有问题。如果遇到此类问题,请直接添加软件包以修复它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-30
相关资源
最近更新 更多