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

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

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

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


当前回答

此警告意味着两个项目引用相同的程序集(例如System.Windows.Forms),但这两个项目需要不同的版本。你有几个选择:

Recompile all projects to use the same versions (e.g. move all to .Net 3.5). This is the preferred option because all code is running with the versions of dependencies they were compiled with. Add a binding redirect. This will suppress the warning. However, your .Net 2.0 projects will (at runtime) be bound to the .Net 3.5 versions of dependent assemblies such as System.Windows.Forms. You can quickly add a binding redirect by double-clicking on error in Visual Studio. Use CopyLocal=true. I'm not sure if this will suppress the warning. It will, like option 2 above, mean that all projects will use the .Net 3.5 version of System.Windows.Forms.

这里有几个方法来识别不合适的推荐人:

您可以使用一个实用程序,例如在 https://gist.github.com/1553265 另一个简单的方法是设置Build 输出冗长(工具,选项,项目和解决方案,构建和 运行,MSBuild项目构建输出详细,详细)之后 构建时,在输出窗口中搜索警告,并查看 文字就在上面。(向保罗亚致敬,她在 对这个答案的评论)。

其他回答

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

当我的项目引用NETStandardLibrary时,我遇到了这样的问题,其中一个引用的程序集发布了netcore。只要把它作为网络标准发布,问题就解决了

如果你使用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]

基本上,当您引用的程序集将“Copy Local”设置为“True”时,就会发生这种情况,这意味着DLL的副本与exe一起放置在bin文件夹中。

由于Visual Studio也会复制所引用程序集的所有依赖项,因此最终可能会引用同一个程序集的两个不同构建。如果您的项目在不同的解决方案中,因此可以单独编译,则更有可能发生这种情况。

我解决这个问题的方法是在组装项目中将Copy Local设置为False。只针对可执行文件/web应用程序,在这些应用程序中,您需要运行成品的程序集。

希望这有意义!

如果使用NuGet,我所要做的是:

右键单击项目,单击管理NuGet包.. 点击右上角的齿轮 在包源上方的NuGet包管理器中单击“常规”选项卡 检查“跳过应用绑定重定向”在绑定重定向 清理重建,警告就没了

容易peasy