[英]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
I have a solution that contains a library and 2 applications. 我有一个包含一个库和2个应用程序的解决方案。 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.
这些应用程序代表相同的程序,其中一个程序通过UAP10定位于Windows App Store,另一个程序则针对使用.Net Framework 4.6.1的Microsoft Windows PC。 I'm using Visual Studio 2017.
我正在使用Visual Studio 2017。
The UWP version compiles and runs fine. UWP版本可以编译并正常运行。
Initially, the .Net Framework 4.6.1 compiles and runs. 最初,.Net Framework 4.6.1编译并运行。 However, when I make a call to File.Open from System.IO, I get the following error message:
但是,当我从System.IO调用File.Open时,出现以下错误消息:
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.
System.IO.FileNotFoundException:'无法加载文件或程序集'System.IO.FileSystem,版本= 4.0.1.0,区域性=中性,PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一。 The system cannot find the file specified.'
该系统找不到指定的文件。'
The code block with File.Run is within the library code (.Net Standard 1.4). File.Run的代码块在库代码(.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 4.6.1的应用程序中使用.Net Standard 1.4库。
As a workaround, I tried installing the Nuget package for System.IO in the .Net Framework application. 解决方法是,我尝试在.Net Framework应用程序中为System.IO安装Nuget程序包。 System.IO Version 4.0.1.0 is not even an option.
System.IO版本4.0.1.0甚至都不是一个选项。 There is a version 4.0.10, but it doesn't work when this Nuget package is installed.
有一个版本4.0.10,但在安装此Nuget软件包时不起作用。
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? 因此,如何在引用.Net Standard 1.4库中的System.IO代码的.Net Framework 4.6.1应用程序中正确引用System.IO操作?
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. 当引用的项目需要覆盖覆盖的系统定义的类型,但是没有绑定重定向可以正确设置此设置时,“经典” csproj项目通常会发生这种情况。 When installing all the packages into a .net framework app (eg
NETStandard.Library
or NETStandard.Library.NETFramework
(for upcoming .NET Standard 2.0)), this should be done automatically. 将所有软件包安装到.net框架应用程序(例如
NETStandard.Library
或NETStandard.Library.NETFramework
(对于即将推出的.NET Standard 2.0))时,应自动完成此操作。
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): 要强制生成绑定重定向,请将其添加到.NET Framework项目的csproj文件中(如果它是一个可执行项目,则第二个属性应该无关紧要,但不会受到损害):
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.