【发布时间】:2017-04-10 00:59:14
【问题描述】:
我有 2 个简单的项目,一个在 DotNet Core(比如说 CoreProject)中,另一个在 .net 4.5.2 中(比如说 OldCode)。我能够引用这些项目,但是当我从 CoreProject 调用 OldCode 时遇到以下错误:
System.IO.FileNotFoundException occurred
HResult=0x80070002
Message=Could not load file or assembly 'System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
The system cannot find the file specified.
我尝试将 System.Configuration 添加到项目中,但我不知道应该将它添加到哪个文件。我没有 project.json。只有我拥有的配置文件是:launchSettings.json 和 appsettings.json。我用 nuGet 添加 System.Configuration 因为它是旧版本。
当我运行命令 dotnet restore 以将依赖项添加到 System.Configuration 时,我应该将引用放在哪里?
【问题讨论】:
-
您不能在 .NET Core 中使用 .NET 4.5.2 库。它们必须是 .NET Standard Library/PCL(然后可以将 netstandard1.0 定位到 1.6,映射到 .NET >=4.5 的某些功能集),或者您的 ASP.NET Core 项目也必须以 .NET >=4.5 为目标
-
@Tseng 所以如果我有一些不能用 .net Core 编写的代码,我将无法引用 4.5.2 中的项目?
-
是的。这就是为什么您必须将代码放入 NETStandard 库的原因,这将确保您的库仅使用在所有平台上都可用的 API(当您以 netstandard1.x 为目标时)