在库中使用 .Net Standard 1.4 和在应用程序中使用 .Net framework 4.6.1 时,无法加载文件 System.IO.FileSystem, Version=4.0.1.0 [英] When using .Net Standard 1.4 in a library and .Net framework 4.6.1 in and application, unable to load file System.IO.FileSystem, Version=4.0.1.0

查看:18
本文介绍了在库中使用 .Net Standard 1.4 和在应用程序中使用 .Net framework 4.6.1 时,无法加载文件 System.IO.FileSystem, Version=4.0.1.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一个库和 2 个应用程序的解决方案.这些应用程序代表相同的程序,其中一个通过 UAP10 构建以针对 Windows App Store,另一个针对使用 .Net Framework 4.6.1 的 Microsoft Windows PC 构建.我使用的是 Visual Studio 2017.

I have a solution that contains a library and 2 applications. The applications represent the same program, with one built to target the Windows App Store through UAP10 and the other built to target a Microsoft Windows PC using .Net Framework 4.6.1. I'm using Visual Studio 2017.

  • 我将库项目目标设置为 .Net 标准 1.4.
  • 我将 UWP 应用程序设置为面向 Windows 10 Aniversary Edition (10.0; Build 14393), Min version Windows 10 (10.0; Build 10586).
  • 我将通用 Windows 应用程序设置为面向 .Net Framework 4.6.1.

UWP 版本编译并运行良好.

The UWP version compiles and runs fine.

最初,.Net Framework 4.6.1 编译并运行.但是,当我从 System.IO 调用 File.Open 时,收到以下错误消息:

Initially, the .Net Framework 4.6.1 compiles and runs. However, when I make a call to File.Open from System.IO, I get the following error message:

System.IO.FileNotFoundException: '无法加载文件或程序集'System.IO.FileSystem,版本=4.0.1.0,文化=中性,PublicKeyToken=b03f5f7f11d50a3a' 或其依赖项之一.这系统找不到指定的文件.'

System.IO.FileNotFoundException: 'Could not load file or assembly 'System.IO.FileSystem, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'

带有 File.Run 的代码块位于库代码 (.Net Standard 1.4) 中.我不确定是什么导致了这个问题.我认为我可以在引用 .Net Framework 4.6.1 的应用程序中使用 .Net Standard 1.4 库.

The code block with File.Run is within the library code (.Net Standard 1.4). I'm not sure what is causing the problem. I thought that I could use .Net Standard 1.4 libraries within an application that references .Net Framework 4.6.1.

作为一种解决方法,我尝试在 .Net Framework 应用程序中安装 System.IO 的 Nuget 包.System.IO 版本 4.0.1.0 甚至不是一个选项.有一个 4.0.10 版本,但是安装了这个 Nuget 包后它不起作用.

As a workaround, I tried installing the Nuget package for System.IO in the .Net Framework application. System.IO Version 4.0.1.0 is not even an option. There is a version 4.0.10, but it doesn't work when this Nuget package is installed.

那么,如何在引用 .Net Standard 1.4 库中的 System.IO 代码的 .Net Framework 4.6.1 应用程序中正确引用 System.IO 操作?

So, how do I properly reference System.IO operations within a .Net Framework 4.6.1 application that references the System.IO code within a .Net Standard 1.4 library?

推荐答案

当引用的项目需要覆盖覆盖系统定义的类型但不存在正确设置的绑定重定向时,这通常发生在经典"csproj 项目中.将所有包安装到 .net 框架应用程序中时(例如 NETStandard.LibraryNETStandard.Library.NETFramework(适用于即将推出的 .NET Standard 2.0)),应该这样做自动.

This usually happens with "classic" csproj projects when referenced projects require overwritten override system defined types but no binding redirects are present that set this up correctly. When installing all the packages into a .net framework app (e.g. NETStandard.Library or NETStandard.Library.NETFramework(for upcoming .NET Standard 2.0)), this should be done automatically.

要强制生成绑定重定向,请将其添加到 .NET Framework 项目的 csproj 文件中(如果是可执行项目,则第二个属性应该无关紧要但不会造成伤害):

To force generation of binding redirects, add this to the csproj file of the .NET Framework project (if it is an executable project, the second property should be irrelevant but it doesn't hurt):

<PropertyGroup>
  <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>

这篇关于在库中使用 .Net Standard 1.4 和在应用程序中使用 .Net framework 4.6.1 时,无法加载文件 System.IO.FileSystem, Version=4.0.1.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆