在库中使用.Net Standard 1.4并在应用程序中使用.Net Framework 4.6.1时,无法加载文件System.IO.FileSystem,版本= 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

查看:238
本文介绍了在库中使用.Net Standard 1.4并在应用程序中使用.Net Framework 4.6.1时,无法加载文件System.IO.FileSystem,版本= 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),最低版本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的代码块在库代码(。网络标准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.Library NETStandard.Library.NETFramework (for

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,版本= 4.0.1.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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