由于 EntityFramework 的不同版本,.NET Core 生成警告
.NET Core build warning due to different versions of EntityFramework
使用 VS 2019,我的几个项目在编译时生成此构建警告:
5>C:\Program Files (x86)\Microsoft Visual
Studio19\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2081,5):
warning MSB3277: Found conflicts between different versions of
"Microsoft.EntityFrameworkCore" that could not be resolved. These
reference conflicts are listed in the build log when log verbosity is
set to detailed.
由于日志不是真的...冗长(即使在详细模式下),我调查了一下,似乎错误是由 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
测试项目缺少对问题包的引用。仅将它们添加到您在第二个项目中引用的项目中是不够的。
所以将它们添加到测试项目中:
<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。
使用 VS 2019,我的几个项目在编译时生成此构建警告:
5>C:\Program Files (x86)\Microsoft Visual Studio19\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2081,5): warning MSB3277: Found conflicts between different versions of "Microsoft.EntityFrameworkCore" that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.
由于日志不是真的...冗长(即使在详细模式下),我调查了一下,似乎错误是由 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
测试项目缺少对问题包的引用。仅将它们添加到您在第二个项目中引用的项目中是不够的。
所以将它们添加到测试项目中:
<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。