在Ubuntu上为.net安装newtonsoft-json

本文关键字:安装 newtonsoft-json net 上为 Ubuntu | 更新日期: 2023-09-27 18:15:29

我只是想解析一些JSON,我从c#的API调用返回。我在Ubuntu上使用。net。为此,我尝试使用

安装newtonsoft-json。
nuget install Newtonsoft.Json

库安装成功。然而,当我运行程序时,我得到以下错误:

error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)

这是怎么回事?如何让。net识别新的库?

另外,我并不是特别喜欢这个库,我只是想在Ubuntu的。net中解析一个JSON字符串。还有其他想法吗?

在Ubuntu上为.net安装newtonsoft-json

在终端(这是OpenSUSE控制台/终端)上运行此命令。但是,同样的概念也适用于Ubuntu。

xxxx@localhost:~/Path/To/Project>dotnet add package Newtonsoft.Json

xxxx@localhost:~/Path/To/Project>dotnet restore

我终于想通了!我只是手动修改了我的包。然后输入dotnet restore . json文件。在那之后,newtonsoft-json工作正常

此dll在Mono gac中可用。您需要添加新的引用,否则将得到错误消息。如果您正在使用corefx,那么请使用。net还原。包将被加载。查看链接

这对我有用:

sudo apt-get install Newtonsoft.Json