面向 netstandard2.0 时的 FileNotFoundException 程序集,但不面向多目标时

问题描述

我有一个当前面向 .netstandard2.0 (<TargetFramework>netstandard2.0</TargetFramework>) 的项目,当我尝试运行它时返回以下错误

System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime,Version=4.1.2.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Runtime,PublicKeyToken=b03f5f7f11d50a3a' ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime,Version=4.0.0.0,PublicKeyToken=b03f5f7f11d50a3a'

但是,当我执行这样的多目标时:<TargetFrameworks>netstandard2.0;net472</TargetFrameworks> 可以解决这些问题。

谁能解释为什么会发生这种情况?我不知道是否需要针对 netstandard2.0 和 net472,我还在 App.config 中尝试了以下内容,这要求我重定向大量程序集:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="4.0.0.0-4.1.2.0" newVersion="4.3.0" />
      </dependentAssembly>
    </assemblyBinding>

在这里做错了什么?是否可以使用 netstandard2.0 而不会出现这些 System.* 程序集问题?我使用的依赖我相信都支持 netstandard2.0

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)