pet*_*ter 16 .net c# visual-studio-2013
为了在Mono中部署我的项目,我已经将它降级为.Net 4.0,因为我已经完成了我正在引用的库(CommonUtils).但是,我仍然遇到以下异常:
无法解析主要引用"CommonUtils",因为它对程序集"Newtonsoft.Json,Version = 4.5.0.0,Culture = neutral,PublicKeyToken = 30ad4fe6b2a6aeed"具有间接依赖性,它是针对".NETFramework,Version = v4构建的" .5"框架.这是比当前目标框架".NETFramework,Version = v4.0"更高的版本.
我试图解决这个问题:
这些都没有帮助.
这两个项目都设置为.Net 4.0.基准是通过复制编译组件CommonUtils成一个"ExternalLibraries" -folder,由于该DLL是在其他项目中也被使用.
右键单击Newtonsoft.Json.dll - 它bin与CommonUtils一起移动到该文件夹- 显示在详细信息/文件描述中:Json.NET .NET 4.0
我很确定我拥有一切正确的.net 4.0和Visual Studio也允许我添加库并支持我自动完成,只是编译抛出上述警告.作为警告的结果,我突然得到异常,即CommonUtils引用的类型都不存在
找不到命名空间名称'CommonUtils'的类型(您是否缺少using指令或程序集引用?)
还有什么我可以尝试使这项工作?
PS:几年前我遇到过类似的问题,一个旧的程序集用于编译,并通过从头开始设置窗口和视觉工作室来"解决"它,但这次我觉得不喜欢这样做.
更新:
它适用于另一台计算机:我已经通过USB Stick将文件夹结构带到另一台具有相同操作系统(Windows 8.1)和相同Visual Studio 2013的计算机 - 据我所知,两台计算机都应安装所有更新 - 它有效.
将USB Stick与成功编译的项目一起带回我的电脑 - 我仍然遇到同样的错误.
(我明白,这意味着两台计算机都不可能安装相同的所有东西,但我不知道如何找到差异,也许有些暗示这可能是错误的?)
更新2:
进程资源管理器没有太多帮助,但是当我使用诊断日志编译所有内容时,我想我得到了关键提示:
...
5> Unified primary reference "Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed". (TaskId:158)
5> Using this version instead of original version "4.5.0.0" in "C:\<SolutionFolder>\packages\WebGrease.1.6.0\lib\WebGrease.dll" because of a binding redirect entry in the file "Web.config". (TaskId:158)
5> Using this version instead of original version "4.5.0.0" in "C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies\System.Web.Http.dll" because of a binding redirect entry in the file "Web.config". (TaskId:158)
5> Using this version instead of original version "4.5.0.0" in "C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies\System.Net.Http.Formatting.dll" because of a binding redirect entry in the file "Web.config". (TaskId:158)
5> Resolved file path is "C:\<SolutionFolder>\packages\Newtonsoft.Json.6.0.3\lib\net40\Newtonsoft.Json.dll". (TaskId:158)
5> Reference found at search path location "{HintPathFromItem}". (TaskId:158)
5> Found related file "C:\<SolutionFolder>\packages\Newtonsoft.Json.6.0.3\lib\net40\Newtonsoft.Json.xml". (TaskId:158)
5> The ImageRuntimeVersion for this reference is "v4.0.30319". (TaskId:158)
...
Run Code Online (Sandbox Code Playgroud)
但是,我在构建工作的另一台计算机上也得到完全相同的消息.
此外,两台计算机在开头显示此行:
Skipping NuGet package Newtonsoft.Json 6.0.3 since it is already installed.
Run Code Online (Sandbox Code Playgroud)
installed在这种情况下意味着什么?那个NuGet下载了吗?或者它是在GAC的某个地方,但我找不到它?(看评论)
在编译工作的机器上,我还得到了这个输出:
1> Dependency "Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed". (TaskId:17)
1> Resolved file path is "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Blend\Newtonsoft.Json.dll". (TaskId:17)
1> Reference found at search path location "{Registry:Software\Microsoft\.NETFramework,v4.0,AssemblyFoldersEx}". (TaskId:17)
1> For SearchPath "C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies". (TaskId:17)
1> Considered "C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies\Newtonsoft.Json.winmd", but it didn't exist. (TaskId:17)
1> Considered "C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies\Newtonsoft.Json.dll", but it didn't exist. (TaskId:17)
1> Considered "C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies\Newtonsoft.Json.exe", but it didn't exist. (TaskId:17)
1> For SearchPath "{TargetFrameworkDirectory}". (TaskId:17)
1> Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Newtonsoft.Json.winmd", but it didn't exist. (TaskId:17)
1> Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Newtonsoft.Json.dll", but it didn't exist. (TaskId:17)
1> Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Newtonsoft.Json.exe", but it didn't exist. (TaskId:17)
1> For SearchPath "{Registry:Software\Microsoft\.NETFramework,v4.0,AssemblyFoldersEx}". (TaskId:17)
1> Considered AssemblyFoldersEx locations. (TaskId:17)
1> Required by "CommonUtils". (TaskId:17)
1> The ImageRuntimeVersion for this reference is "v4.0.30319". (TaskId:17)
Run Code Online (Sandbox Code Playgroud)
但我没有在编译失败的计算机上看到它
最后更新:
我放弃并重新安装了我的整个系统 - 它现在可以正常工作了,但它没有回答错误的Newtonsoft.Json.dll来自哪里以及为什么它没有出现在GAC中的问题,我终于可以再次研究项目.
我实际上非常失望,它不像maven那么容易,你可以删除一个文件夹,以便让maven重新下载所有的库.
我在VHD上有一个破损系统的图像,所以如果其他人想出了一个很好的解决方案,我可以在VM中试一试.
Mag*_*son 19
我有同样的问题,解决方案是删除Newtonsoft.json.dll位于c:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\v2.3\ref
这被描述为此Connect错误报告中的变通方法.
编辑:原始错误报告已删除,可能是新的/相关/同一问题:https://connect.microsoft.com/VisualStudio/feedback/details/816985