Visual Studio C# 参考警告

发布于 2024-11-18 14:54:44 字数 207 浏览 2 评论 0原文

编译后,我的解决方案有一个警告,如下快照所示。 在此处输入图像描述

双击警告会弹出一个问题,我不知道它是什么。 在此处输入图像描述

如果您了解 VS 在说什么,请分享。

After compiled, my solution has a warning as below snapshot.
enter image description here

Double clicking the warning will popup a question which I have no idea what it is.
enter image description here

If you understand what VS is talking about, please share.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执手闯天涯 2024-11-25 14:54:44

这看起来像是您在解决方案的不同项目中引用了略有不同版本的依赖项。这意味着,当您尝试运行项目时,如果您传递依赖项中具有类型的任何引用,则可能会出现意外错误,因为来自同一程序集的不同版本的类型被认为是不同的。

例如,

Project1 使用版本 1.0 的依赖项 SomeAssembly.dll
Project2 使用依赖项 SomeAssembly.dll 但版本为 1.1
Project2 将 Project1 作为依赖项

项目 2 中的代码尝试将 SomeType 的引用从其代码传递到项目 1 的代码,其中该类型在 SomeAssembly.dll 中定义。 1 引发错误,因为该类型无法识别,因为它来自不同版本的程序集。

您的问题可能比这更微妙,因为编译器可以捕获这种类型的大多数错误,但如果您有复杂的依赖项或使用依赖项注入,编译器可能不一定会发现这样的事情。

Visual Studio 提供了有效的解决方法,将所有依赖项重定向到特定版本。恕我直言,如果您可以自己手动修复它,我会避免进行修复。

您最好仔细检查您的解决方案并检查所有参考文献以确保它们全部匹配版本。您可能需要删除并添加回引用才能使其正常工作,但从长远来看,现在这样做可以避免出现意外问题。

This looks like you've referenced slightly different versions of your dependencies in different projects in your solutions. What this means is that when you try and run your projects you may get unexpected errors if you pass any references with types in the dependencies as types from different versions of the same assembly are considered to be different.

E.g.

Project1 uses dependency SomeAssembly.dll which is Version 1.0
Project2 uses dependency SomeAssembly.dll but at Version 1.1
Project2 has Project1 as a dependency

Code in project 2 tries to pass a reference of SomeType where that type is defined in SomeAssembly.dll from its code to code from project 1. Project 1 throws an error because the type is not recognised as it comes from a different version of the assembly.

Your problem may be more subtle than this since most errors of this type can be caught by the compiler but if you have complex dependencies or use dependency injection the compiler may not necessarily spot things like this.

Visual Studio is offering to effectively do a workaround for you my redirecting the dependencies all to a specific version. IMHO I would avoid taking the fix if you can fix it manually yourself.

You would be much better off going through your solution and checking all your references to ensure they all match version wise. You may need to remove and add back references to get this working properly but doing this now will avoid unexpected problems in the long run.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文