Visual Studio C# 参考警告
编译后,我的解决方案有一个警告,如下快照所示。
双击警告会弹出一个问题,我不知道它是什么。
如果您了解 VS 在说什么,请分享。
After compiled, my solution has a warning as below snapshot.
Double clicking the warning will popup a question which I have no idea what it is.
If you understand what VS is talking about, please share.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这看起来像是您在解决方案的不同项目中引用了略有不同版本的依赖项。这意味着,当您尝试运行项目时,如果您传递依赖项中具有类型的任何引用,则可能会出现意外错误,因为来自同一程序集的不同版本的类型被认为是不同的。
例如,
Project1 使用版本 1.0 的依赖项
SomeAssembly.dll
Project2 使用依赖项
SomeAssembly.dll
但版本为 1.1Project2 将 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.0Project2 uses dependency
SomeAssembly.dll
but at Version 1.1Project2 has Project1 as a dependency
Code in project 2 tries to pass a reference of
SomeType
where that type is defined inSomeAssembly.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.