ServiceStack OrmLite-Mysql 兼容性 (5.4.0) (.net c#)

ServiceStack OrmLite-Mysql Compability (5.4.0) (.net c#)

我们有一个由 .net Framework (4.7.2) 和 .net Standard (2.0) 项目组成的解决方案。根据此页面:http://docs.servicestack.net/templates-corefx#reference-core-packages 我们应该只引用 .Core 包。 在这种情况下,我们需要 ServiceStack.OrmLite 和 ServiceStack.OrmLite.Mysql,因此我安装了 ServiceStack.OrmLite.Core 和 ServiceStack.OrmLite.Mysql.Core。两者都在同一个 5.4.0 版本上。

Image: Installed nugets

然而,这样做时 VS(2017 年和 2019 年 p3)会给我编译错误说明(除其他外,但我认为所有这些都归结为同一个问题):

类型 'IOrmLiteDialectProvider' 存在于 'ServiceStack.OrmLite, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null' 和 'ServiceStack.OrmLite, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587'

我们在这里看到的是其中一个包的 PublicKeyToken=null 而另一个包的密钥为 02c12cbda47e6587。我的问题的根源可能是什么,我是否误解了我应该使用的 nugets 版本,或者这两个包是否与 5.4.0 版本不兼容?

(如果我安装 OrmLite.Mysql.Core 版本 5.2.0 和 OrmLite 5.4.0,项目将编译但在运行时失败,因为它们引用不同版本的 Mysql)。

最后一点,有没有人知道为什么.net 标准包被命名为“核心”。对我来说,得知核心包可以在我的 .net Framework 项目中使用是令人困惑的,因为 .net Core 和 .net Framework 项目不兼容,而 .net Core 和 .net Framework(当然)都可以使用 .net Standard。

此异常表示您有一个项目试图在同一项目中同时引用 ServiceStack.OrmLiteServiceStack.OrmLite.Core 包,而您永远不应这样做。

请阅读此 existing answer carefully, the .Core packages should only be referenced when trying to Run ASP.NET Core Apps on the .NET Framework,但在任何时候你都不能拥有同时引用 .Core 和非 .Core 包的项目,你可以在不同平台之间共享依赖项的唯一方法是通过多目标。

您可以从以下位置找到共享通用多目标项目的解决方案示例:

https://github.com/ServiceStackApps/HelloMobile#servicestack-server-app

这显示了多个主机如何通过多目标共享相同的 Server.Common and ServiceModel.csproj 项目的示例:

  <PropertyGroup>
    <TargetFrameworks>net46;netstandard2.0</TargetFrameworks>
    <RootNamespace>Server</RootNamespace>
  </PropertyGroup>

.NET Core and ASP.NET Core on .NET Framework will end up using the netstandard2.0 builds of the common projects whilst the classic ASP.NET and HttpListener 主持人最终将使用 net46 版本。