我目前正在开发一个。net应用程序,它由20个项目组成。其中一些项目是使用。net 3.5编译的,其他一些仍然是。net 2.0项目(到目前为止没有问题)。

问题是,如果我包含一个外部组件,我总是得到以下警告:

发现同一依赖程序集的不同版本之间存在冲突。

这个警告到底是什么意思,有没有可能排除这个警告(比如在源代码文件中使用#pragma disable)?


当前回答

如果你使用Nuget来管理依赖项,我还有另一种方法。我发现有时候VS和Nuget不匹配,Nuget无法识别你的项目不同步。的包。config会说一件事,但在References - Properties中显示的路径将指示其他内容。

如果你愿意更新你的依赖项,请执行以下操作:

From Solution Explorer, right click the Project and click 'Manage Nuget Packages' Select 'Installed packages' tab in left pane Record your installed packages You may want to copy your packages.config to your desktop first if you have a lot, so you can cross check it with Google to see what Nuget pkgs are installed Uninstall your packages. Its OK, we're going to add them right back. Immediately install the packages you need. What Nuget will do is not only get you the latest version, but will alter your references, and also add the binding redirects for you. Do this for all of your projects. At the solution level, do a Clean and Rebuild.

您可能希望从较低的项目开始,然后逐步到较高级别的项目,并在进行过程中重新构建每个项目。

如果你不想更新你的依赖项,那么你可以使用包管理器控制台,并使用语法update - package -ProjectName [yourProjectName] [packageName] -Version [versionNumber]

其他回答

打开“解决方案资源管理器”。 点击“显示所有文件” 扩大“引用” 您将看到一个(或多个)引用与其他引用的图标略有不同。通常情况下,它会有一个黄色的方框,建议你记下它。把它拿掉。 重新添加引用并编译代码。 这是所有。

在我的例子中,MySQL引用有一个问题。不管怎样,我可以在所有可用的引用列表下列出它的三个版本;适用于。net 2.0、。net 4.0和。net 4.5。我遵循了上面的方法1到6,它对我很有效。

这也发生在我身上。一个dll被引用了两次:一次直接(在引用中),一次间接(被另一个引用的项目引用)。 我删除了直接参考,清洗和重建解决方案。固定的问题。

我只是有这个警告消息,清理解决方案和重新编译(构建->清洁解决方案),它消失了。

我也有同样的问题,我通过在web.config中更改以下内容来解决。

这发生在我身上,因为我正在使用Newtonsoft运行应用程序。Json 4.0

来自:

<dependentAssembly>
  <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>

To:

<dependentAssembly>
  <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="4.5.0.0" />
</dependentAssembly>

我也有同样的问题。在项目的“obj”文件夹中,我将文件夹“Debug”重命名为“Debug_OLD”并重新构建。一个新的“Debug”文件夹会自动生成,问题也就解决了。