gpt4 book ai didi

c# - Newtonsoft.JSON v9.01 + FileNotFoundException(.NET 核心类库)

转载 作者:可可西里 更新时间:2023-11-01 08:26:16 25 4
gpt4 key购买 nike

(VS2015 更新 3 + 补丁)

我有一个普通的 .NET 控制台应用程序 (.NET 4.6) 并引用了一个面向 NetStandard v1.3 的 .NET 核心类库。类库引用了 Newtonsoft.JSON。

{
"version": "1.0.0-*",

"dependencies": {
"NETStandard.Library": "1.6.0",
"Newtonsoft.Json": "9.0.1"
},
"buildOptions": { "platform": "anycpu" },

"frameworks": {
"netstandard1.3": {
"imports": "dnxcore50"
}
}
}

引用的 NewtonSoft.JSON 包部署在这里:

C:\Users\UserAccount\.nuget\packages\Newtonsoft.Json\9.0.1

异常:

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in DotNetConsoleApplication.exe

Additional information: Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.

我猜 .net 核心库会引用 netstandard1.0 文件夹中的 dll。

enter image description here

最佳答案

创建 NuGet 包是一种解决方案,但不是最简单的。

Microsoft 终于承认这是一个问题并且will fix它有望在 NuGet 版本 4.0.1 中出现,这是 VS 2017 发布后对 NuGet 4 的首次更新。

现在最干净的解决方法是添加 <RestoreProjectStyle>PackageReference</RestoreProjectStyle>到遗留项目。然而according to Rob Relyea MS 将在 RTM 之后忽略此属性,因此另一个解决方法是 <PackageReference Update="PlaceholderToConvinceThisProjectToGetTransitivePackageReferenceFromProjectReferences"/> .

关于c# - Newtonsoft.JSON v9.01 + FileNotFoundException(.NET 核心类库),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38349276/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com