开发者

Referencing both an old version and new version of the same .NET DLL

Consider the following situation:

WidgetCompany produced a .NET DLL in 2006 called Widget.dll, version 1.0. I consumed this Widget.dll file throughout my .NET application. Over time, WidgetCompany has been updating Widget.dll, I never bothered to keep up, continuing to ship version 1.0 of Widget.dll with my software. It's now 2011, my project is now a .Net 3.5 application and WidgetCompany has come out with Widget.dll version 2.0. It looks and functions almost identical to Widget.dll version 1.0, using all the same namespaces and type names from before.

However, Widget.dll version 2.0 has many run-time breaking changes since 1.0 and I cannot simply cut over to the new version; however, I don't want to continue developing against the 1.0 version and therefore keep digging myself deeper in the hole. What I want to do is do all new development in my project with Widget.dll version 2.0, whilst keeping Widget.dll version 1.0 around until I find time to convert all of my 1.0 consumption to the newer 2.0 code.

Now, for starters, I obviously cannot simply reference both Widget.dll (Ver 1.0) and Widget.dll (Ver 2.0) in Visual Studio. Doing so gives me the following message: "A reference to 'Widget.dll' could not be added. A reference to the component 'Widget' already exists in the project." To work around that, I can simply rename version 2.0 Widget.dll to Widget.3.dll. But this is where I'm stuck. Any attempts to reference types found in "the dll" leads to ambiguity and the compiler obviously doesn't have any clue as to what I really want in this or that case.

Is there something I can do that gives a DLL a new "root" Namespace or something? For example, if I could say "Widget.dll has a new root namespace of Legacy" then I could update existing code to reference the types found in Legacy.<RootNamespace> namespace while all new code could simply reference types from the <RootNamespace> namespace. Pipe dream or reality? Are there other solutions to situations this (besides开发者_如何学C "don't get in this situation in the first place")?


Off the top of my head this is what I'd do.

Change the name of the Widget for the new version and leave the old one the way it is to keep your legacy code working.

Then create a project that is a wrapper of the new widget DLL.

Add this new wrapper project to my existing solution and then reference that wrapper from the existing code and then the compiler should ignore the type clashes because the new widget is in a different project.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜