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


当前回答

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.

其他回答

在我的解决方案中有太多的项目需要逐一检查和单独更新,所以我通过以下方法解决了这个问题:

右键单击我的解决方案并选择“管理解决方案的NuGet包…” 进入更新选项卡 找到受影响的包并选择Update 单击OK,这将使包的所有实例保持最新

我得到类似的编译器错误。一旦我将dll文件的依赖项目添加到解决方案中,问题就解决了。

帮助我的是,我进入包管理器解决方案,查看导致问题的安装包。我看到有几个项目引用了相同的包,但是版本不同。我根据自己的需要把它们排列起来,这很有效。

如果您更改了程序集版本或复制了错误中声明的托管库的不同版本,则以前编译的文件也可能引用了错误的版本。一个“重建所有”(或删除你的“bin”和“obj”文件夹在前面的评论中提到)应该解决这个问题。

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

构建——>重建方案