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


当前回答

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

您的解决方案中有多个项目 有一个项目(项目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来安装它。

其他回答

您的程序集是否正确签名?

要检查这一点,在项目上按Alt+Enter(或右键单击,然后Properties)。点击“签名”。验证复选框“签名程序集”已选中,强名称密钥文件已选中,且“仅延迟签名”未选中。

这里有一个不同的方法来解决这个问题:

右键单击项目并选择“卸载项目”选项。您将注意到您的项目变得不可用。 右键单击不可用项目并选择“Edit”选项。 向下滚动到包含所有资源标记的“< ItemGroup >”标记。 现在转到已经显示在错误列表中的引用,您将注意到它使用了单个标记(即< reference Include="assemble_name_here, Version=0.0.0.0, Culture=neutral" / >)。 更改为如下所示:

.

<Reference Include="assemble_name_here, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL" >
    < Private > True < / Private >
    < HintPath > path_here\assemble_name_here.dll < / HintPath >
< / Reference >

保存您的更改,再次右键单击不可用的项目,然后单击“重新加载项目”选项,然后构建。

我就有这个问题。这是因为我有许多项目指向相同的组装,但从不同的版本。我解决它选择相同版本的所有项目在我的解决方案。

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.

尝试update-package -重装-ignoredependencies