如何在 ASP.NET 应用程序中使用同一程序集的两个版本?
我有一个旧版本的 asp.net 组件。我想在旧版本的同时使用新版本。
我使用 gacutil.exe 命令将这两个程序集放入 GAC 中。现在,我想在每个 .aspx
页面中加载该组件的特定版本。
我该怎么做?
我可以使用这个代码吗?
<%@ Register assembly="<dllname>, Version=2.5.0.0, Culture=neutral,
PublicKeyToken=......." Namespace="<dllNamespace>." TagPrefix="WG" %>
I have an old version of an asp.net component. I would like to use a newer version alongside the old version.
I put both assemblies in the GAC using the gacutil.exe
command. Now, I would like to load a specific version of the component inside each .aspx
page.
How can I do this?
Can I use this code?
<%@ Register assembly="<dllname>, Version=2.5.0.0, Culture=neutral,
PublicKeyToken=......." Namespace="<dllNamespace>." TagPrefix="WG" %>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用以下代码在运行时创建所需版本的对象,
您可以参考 Activator.CreateInstance 或 使用 Activator.CreateInstance 从字符串名称创建对象< /a>
You can use create an object of version you want in runtime using the following code
you can refer to Activator.CreateInstance or Use Activator.CreateInstance to Create Objects from a String Name
从技术上讲是的,您所询问的
Register
属性是可能的。然而,这并不是一条真正容易走的路,因为它会充满奇怪的限制。我的建议是,如果可能的话,要么根本不这样做,要么隔离用户控件中不同版本的控件,这些控件可以存在于单独的类库中。您将获得如下程序集名称:
controls_for_1_5
和controls_for_2_5
,并在此处创建对该程序集的引用。 (当然,这些名称供您选择)。如果您不小心,这种方式仍然会导致奇怪的错误,例如Can't cast 'Namespace.ClassA' to 'Namespace.ClassA'
(是的,它们是相同的,这不是拼写错误)。不过,我的建议是不要这样做,除非您对 .NET 框架的更深层部分有真正深入的了解。
Technicly yes, It's possible with the
Register
property you are asking about. It is however not a really easy path to walk as it will be riddled with strange limitations.My suggestion would be to either not do it at all if possible or else isolate the controls of different versions in usercontrols that can live in separate class libraries. You'd get assembly names like:
controls_for_1_5
andcontrols_for_2_5
and in here you create references to the assembly. (The names are of course for you to choose). This way can still cause strange errors likeCan't cast 'Namespace.ClassA' to 'Namespace.ClassA'
(Yes they are the same, it's not a typo) if your not carefull.Still my advise would be to not do it unless you have a real strong understanding of the deeper parts of the .NET framework.