我试图使用c# 4.0编译我的excel插件,并在Visual Studio中构建我的项目时开始遇到这个问题。重要的是要告诉你,我以前从来没有遇到过这个问题。什么会导致这种情况发生?


当前回答

如果依赖项不匹配,请在解决方案级别的NuGet包管理器中检查Update和consolidated选项卡,协调所有这些。

其他回答

您需要使用密钥对程序集进行签名。进入选项卡签名下的项目属性:

卸载和重新加载项目的问题解决了它为我。

I recently hit this problem. In my case, I have NuGet packages on different assemblies. What I had was different versions of the same NuGet packages associated with my own assemblies. My solution was to use the NuGet package manager upon the Solution, as opposed to the individual projects. This enables a "consolidation" option, where you can upgrade your NuGet packages across as many projects as you want - so they all reference the same version of the assembly. When I did the consolidations, the build failure disappeared.

如果你试了这个问题的所有其他答案,你会:

您的解决方案中有多个项目 有一个项目(项目a)引用另一个项目(项目B),后者的项目引用一个NuGet包。 在项目A中,您使用Intellisense/ReSharper引入项目B中引用的NuGet包的引用(当项目B中的方法返回由NuGet包提供的类型并且该方法在项目A中使用时,这可能会发生) 通过NuGet包管理器(或CLI)更新NuGet包。

...你可能在你的项目的引用中有不同版本的NuGet包DLL,因为Intellisense/ReSharper创建的引用将是一个“正常的”引用,而不是预期的NuGet引用,所以NuGet更新过程不会发现或更新它!

要解决这个问题,请删除项目A中的引用,然后使用NuGet安装它,并确保所有项目中的NuGet包都是相同的版本。(如回答中所述)


生活小贴士:

当ReSharper/Intellisense建议添加一个引用到你的项目时,这个问题就会出现。它可能比上面的例子复杂得多,多个交织的项目和依赖关系使其难以跟踪。如果ReSharper/Intellisense建议的引用实际上来自NuGet包,使用NuGet来安装它。

当我在更新WindowsAPICodePack后遇到这种情况时,我只是重新构建了解决方案。

构建——>重建方案