C# 为什么我不能将 newtonsoft.Json.dll 引用添加到我的项目中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18230014/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 11:34:54  来源:igfitidea点击:

why cant i add the newtonsoft.Json.dll ref to my project?

c#jsonvisual-studio-2010referencejson.net

提问by John

please view http://www.youtube.com/watch?v=6MRzbJBvM7cand jump to 1.25.

请查看http://www.youtube.com/watch?v=6MRzbJBvM7c并跳转到 1.25。

Im trying to add a reference 'Newtonsoft.Json.dll' I have followed what he has asked. which adds this ref from 'browse' tab to 'recent' tab. If i look at the list of refs from the ref list it is listed but with a yellow flag.

我试图添加一个参考'Newtonsoft.Json.dll' 我已经按照他的要求进行了操作。它将此引用从“浏览”选项卡添加到“最近”选项卡。如果我查看参考列表中的参考列表,它会列出但带有黄色标志。

When i hold the cursor over the flag it says: not available as it does not exist, or is not built?? So I have removed it from the list of ref's and try to re-add it.

当我将光标悬停在标志上时,它说:不可用,因为它不存在,或者没有构建?因此,我已将其从 ref 列表中删除并尝试重新添加它。

It only appears in the 'recent' section and when I add it, I get:

它只出现在“最近”部分,当我添加它时,我得到:

A reference to 'Newtonsoft.Json.dll' could not be added.?

无法添加对“Newtonsoft.Json.dll”的引用。?

Any ideas guys?

有什么想法吗?

采纳答案by Groostav

Its probablysomething in your build system: the dll is likely getting cleaned (as in deleted by a rebuild), or is in a directory that isn't under your solution, or simply isn't getting copied to the output directory.

可能在您的构建系统中:dll 可能会被清除(如通过重建删除),或者位于不在您的解决方案下的目录中,或者只是没有被复制到输出目录。

I'm sorry I don't have a more specific piece of advice. What I'm going to do though is suggest you use a shot-gun to kill a mosquito: use NuGet. In C# with Visual Studio (or any other .net IDE), you really want to use the nuget package manager, since it works so well.

对不起,我没有更具体的建议。不过,我要做的是建议您使用霰弹枪杀死蚊子:使用NuGet。在带有 Visual Studio(或任何其他 .net IDE)的 C# 中,您确实想使用 nuget 包管理器,因为它运行良好。

  1. Install the visual studio extension,
  2. right click on your solution (dont do the project, do the solution)
  3. select 'Manage Nuget Packages for Solution'
  4. click 'online', in the search box type 'newtonsoft'
  5. click 'Install' on 'Json.NET' (probably, what your looking for might be in another package, I'll ask you to track it down).
  1. 安装visual studio扩展,
  2. 右键单击您的解决方案(不要做项目,做解决方案)
  3. 选择“管理解决方案的 Nuget 包”
  4. 点击“在线”,在搜索框中输入“newtonsoft”
  5. 单击“Json.NET”上的“安装”(可能您要查找的内容可能在另一个包中,我会要求您进行跟踪)。

This will put it in a library directory, include it in the build path, and allow you to use the Intelli sense to auto-add the appropriate reference from your project.

这会将它放在一个库目录中,将它包含在构建路径中,并允许您使用智能感知从您的项目中自动添加适当的引用。

回答by will

Make sure that the your project target framework is set to the correct version. It might be that your target .NET framework for the project is lower than what the Newtonsoft dll was built under. Right click on your project and see what it's set at. You'll need to go view the properties.

确保您的项目目标框架设置为正确的版本。可能是项目的目标 .NET 框架低于 Newtonsoft dll 的构建框架。右键单击您的项目并查看它的设置。你需要去查看属性。

回答by werner

OK, this is a stupid answer, but sometimes you make stupid mistakes ...: if you have several sub-projects in your solution, make sure you add the reference to the right one (or to all) !

好的,这是一个愚蠢的答案,但有时您会犯愚蠢的错误...:如果您的解决方案中有多个子项目,请确保将引用添加到正确的一个(或全部)!

回答by user3778216

Check to see if the Json.net is already install in your project.

检查 Json.net 是否已安装在您的项目中。

If it is already installed go and remove the "package" entry from "packages.config" file. Now go to NuGet "Package Manager Console" and install the new package using the following command:

如果已经安装,请从“packages.config”文件中删除“package”条目。现在转到 NuGet“包管理器控制台”并使用以下命令安装新包:

PM> Install-Package Newtonsoft.Json {Your Project Name} 6.0.3 nuget.org

PM> 安装包 Newtonsoft.Json {您的项目名称} 6.0.3 nuget.org

If it is not installed, goto NuGet and search for JSon.Net and select the project and click install.

如果未安装,请转到 NuGet 并搜索 Json.Net 并选择项目并单击安装。

Sreekanth

斯里坎特

回答by Jo?o Bruno Abou Hatem de Liz

I had the same problem.

我有同样的问题。

Nuget works, but for older Visual Studios, such as 2005/2008, it can be tricky (And that, unfortunately, was my case).

Nuget 可以工作,但是对于较旧的 Visual Studio,例如 2005/2008,它可能很棘手(不幸的是,这就是我的情况)。

I downloaded Json.NET here. Inside binaries, choose the one that matches your .Net Framework version, add the dll inside a folder of your project (e.g. lib), and include it as a reference. Then, have fun!

在这里下载了 Json.NET 。在二进制文件中,选择与您的 .Net Framework 版本匹配的文件,将 dll 添加到您的项目文件夹(例如 lib)中,并将其包含为参考。那么,玩得开心!

回答by shiv roy

In my case i was face the same problem then i am able to resolve by flowing the article

在我的情况下,我遇到了同样的问题,然后我可以通过阅读文章来解决

http://microsoft-ssis.blogspot.com/2011/05/referencing-custom-assembly-inside.html

http://microsoft-ssis.blogspot.com/2011/05/referencing-custom-assembly-inside.html

Add the assembly to GAC Before we can use our assembly, we have to add it to the global assembly cache (GAC). Open the Visual Studio 2008 Command Prompt again (for Vista/Windows7/etc. open it as Administrator). And execute the following command. gacutil /i d:\myMethodsForSSIS\myMethodsForSSIS\bin\Release\myMethodsForSSIS.dll

将程序集添加到 GAC 在我们可以使用我们的程序集之前,我们必须将它添加到全局程序集缓存 (GAC)。再次打开 Visual Studio 2008 命令提示符(对于 Vista/Windows7/等。以管理员身份打开它)。并执行以下命令。gacutil /id:\myMethodsForSSIS\myMethodsForSSIS\bin\Release\myMethodsForSSIS.dll