问题描述
所以我有一个被编译为在.NET 3.5中的DLL此实用程序库,它是用我的asp.net 3.5的网站。我创建了一个.NET 4.0 WinForms应用程序来推动数据到网站。我想利用在此WinForms应用程序的实用程序库的功能。
So I have this utility library that is compiled as a dll under .net 3.5 and it is used by my asp.net 3.5 website. I created a .net 4.0 winforms app to push data onto the website. I want to make use of the functionality in the utilities library from this winforms app.
问题在于,当我提及公用事业库,并使用code。在它的智能感知树皮我说,它无法找到该库中的对象。问题是我会切换WinForms应用程序到3.5解决了这个问题,但我使用需要4.0任务。而且因为我的网站和实用程序库中的两个运行3.5和我的网站托管在GoDaddy的,目前只支持asp.net 3.5让编译我的实用工具库4.0下我的WinForms应用程序是行不通的,因为它打破了我的网站。
The problem lies in that when I make reference to the utilities library and use the code in it intellisense barks at me saying that it can't find the objects in that library. The thing is I would switch the winforms app to 3.5 which fixes the problem, but I am using Tasks which require 4.0. And because my website and utilities library both run 3.5 and my website is hosted at godaddy that currently only supports asp.net 3.5 so compiling my utilities library under 4.0 for my winforms app is not going to work because it breaks my website.
我曾尝试在app.config招阿拉useLegacyV2RuntimeActivationPolicy =真正的......
I have tried the app.config trick ala useLegacyV2RuntimeActivationPolicy="true" ...
但是,这并没有帮助。很显然,我可以开始一个新的应用程序项目4.0,并从现有的实用程序库,然后引用新的4.0的实用程序库在我的WinForms应用程序,但是,这令我觉得挺矫枉过正,当所有我想要做的复制code文件被引用库,并使用它的功能。更何况,我会既包含完全相同的code两个实用库,如果我在一个更新code,我需要确保对方也会更新。我可以使用添加文件作为链接,但你的想法。
But that did not help. Obviously I could start a new utilities project for 4.0 and and copy the code files from the existing utilities library then reference the new 4.0 utilities library in my winforms app but, that strikes me as being rather overkill when all I want to do is reference the library and use it's functionality. Not to mention that I would have two utility libraries both containing the exact same code, and if I update the code in one I will need to make sure that the other is also updated. I could use add file as link, but you get the idea.
那么,有什么事我可以尝试,或解决或解决这个问题的任何其他方式?还是我只是将不得不打破和创造公用事业库的克隆相同的4.0。
So is there anything else I could try or any other way to solve or get around this? Or am I just going to have to break down and create a identical clone of the utilities library for 4.0.
推荐答案
您可以使用重定向DLL引用< assemblyBinding>
元素在你的AppConfig的文件,但这是一个湿滑路面。
You can redirect dll references using <assemblyBinding>
element in your appconfig file, but this is a slippery road.
我在类似的情况确实是,我创建在同一目录2个不同的项目文件 - 一个用于4.0(VS2010),另一个是3.5(VS2008)。这样,我在同一组的实际源文件
What I did in a similar situation is that I created 2 different project files in the same directory - one for 4.0 (VS2010) and another for 3.5 (VS2008). This way I have just 2 different project files over the same set of the actual source files
这篇关于参考3.5组件从4.0的WinForms phail的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!