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


当前回答

就我而言,我将项目升级到。net 4.7.2,但仍然使用旧的visual studio版本(2015年)构建。 当我在VS 2019中构建项目时,构建失败消失了。

其他回答

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.

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

这是在更改引用的.dll的版本时引起的。您需要删除目标构建文件夹中的所有项或.dll。

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

右键单击项目并选择“卸载项目”选项。您将注意到您的项目变得不可用。 右键单击不可用项目并选择“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 >

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

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