【发布时间】:2019-07-19 08:56:30
【问题描述】:
我使用 VS 2019,我有一个名为 Foo 的 .NET Standard (2.0) 库项目(使用 ServiceStack NuGet 包)和一个名为 Bar 的主要 .NET Framework (4.7.2) Windows 服务项目(也使用 ServiceStack NuGet)。 Bar 引用了 Foo。 Bar 是一个 Windows 服务和一个 ServiceStack REST 主机,Foo 具有跨解决方案共享的 DTO(它需要 ServiceStack 库用于 [Route] 属性)。
当我尝试在 Bar 中运行任何与 ServiceStack 相关的代码时,我得到:
{"无法加载文件或程序集 'ServiceStack.Interfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null' 或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。(来自 HRESULT 的异常:0x80131040)":"ServiceStack.Interfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null"} System.IO.FileLoadException
尽管在 Bar 的 app.config 中有这个条目(我使用 Bar 的 .csproj 中的 publicKeyToken):
<dependentAssembly>
<assemblyIdentity name="ServiceStack.Interfaces" publicKeyToken="02c12cbda47e6587" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
我怎样才能让这两者一起工作?
编辑:
Foo 和 Bar 中的 ServiceStack NuGet 包都有版本 5.5.0(在 VS 属性中看到的 .NET Framework 的 .dll “版本”是 5.0.0.0)。我尝试过使用和不使用publicKeyToken,我尝试过映射oldVersion="0.0.0.0-5.5.0.0" newVersion="5.0.0.0" 和oldVersion="0.0.0.0-5.5.0.0" newVersion="5.5.0.0"。
输出文件夹中的实际 .dll 具有以下全名:ServiceStack.Interfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587
【问题讨论】:
-
你试过没有
publicKeyToken吗? -
您是否检查过 Bar 和 Foo 是否具有相同的 ServiceStack.Interfaces 的 Nuget 包版本?
-
似乎唯一的选择是将 Foo 转换为 .NET Framework...
-
所以它构建得很好但只在运行代码时失败?如果可能的话,你能否分享一个最小的样本来重现它:)
-
netstandard2.0输出目录中的dll和Bar的输出目录中的dll完全一样吗?
标签: c# .net visual-studio nuget .net-standard