解决程序集冲突问题 -- Visual Studio 项目参考 +具体版本
简短问题:如何使用项目引用但构建我的程序集,以便该引用是特定版本引用?
长问题(更多详细信息):我们正在为我们的一个应用程序开发模块化设置。不同的软件组件集及其依赖项被加载到隔离的 AppDomain 中。
有些库可能会被不同的组件引用。在某些情况下,我们会遇到程序集冲突。即,我们已经加载了最新版本的库和旧版本,并且正在使用的类型之一(组件使用反射实例化)需要获取新版本中不再存在的内容,即名称已更改的类型或其他什么,因此会抛出 TypeLoadException 或其他任何异常,因为它试图从新版本中提取类型,即使旧版本也已显式加载。避免此类问题的方法似乎是引用特定版本。
据我了解,从 Visual Studio 中以这种方式设置引用的方法是将引用上的特定版本属性设置为 true,并且只有当您将 DLL 引用为文件引用时才能完成此操作,而不是作为项目参考。问题是这些其他库仍在开发中,因此我可能也需要在测试期间调试它们。我希望能够完成项目引用允许您做的所有好事情,即导航到定义(实际上主要是这样,这样我就可以在调试时设置断点等)。
<编辑>为了回答 Slak 的问题,是的,我确实需要运行两个版本。在长问题中对此进行了解释。
SHORT QUESTION: How can I use a project reference but build my assembly so the reference is a specific version reference?
LONG QUESTION (more details): We're working on a modular setup for one of our applications. Different sets of software components are loaded, along with their dependencies, into isolated AppDomains.
There are libraries that might be referenced by different components. In some cases, we're running into assembly conflicts. IE we've got the newest version of a library loaded AND an old version and one of the Types being used (components are instantiated using reflection) needs to grab something that's no longer in the new version, ie a type whose name has been changed or something, so a TypeLoadException or whatever is thrown because it's trying to pull the type from the new version even though the old version has also been explicitly loaded. The way to avoid problems like this, it seems, is to reference specific versions.
As far as I understand it, the way to set a reference up this way from Visual Studio is to set the Specific Version property on the reference to true, and this can only be done when you're referencing a DLL as a file reference NOT as a project reference. The problem is that these other libraries are still in development so I'll potentially need to be debugging them too during tests. I want to be able to do all the nice stuff project references let you do ie navigate to definitions (mostly that, really, so i can set breakpoints while debugging and etc).
<Edit> In response to Slak's question, yes I do need to run both versions. It's explained in the LONG QUESTION.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信你所问的是我以前必须面对的事情,但是对于特定于平台的 dll。您可以更轻松地根据您的要求进行调整。
如何使用 MSBuild 引用不同版本的 dll< /a>
I believe what you are asking is something I have had to face before, but for platform specific dlls. You could easier adapt this to your requirements.
How to reference different version of dll with MSBuild
最终有效的解决方案实际上是签署所有有问题的程序集并使用自定义解析逻辑。具体版本确实与此无关。
The solution that ended up working was actually signing all the assemblies in question and using custom resolution logic. Specific Version did indeed have nothing to do with it.