.NET 无需重新编译即可替换依赖程序集?

发布于 2024-08-28 05:08:35 字数 598 浏览 9 评论 0原文

我有一个关于 .NET Framework (2.0) 如何解析依赖程序集的问题。

我们目前正在对一个大型 ASP.NET 应用程序和各种卫星可执行文件进行一些重写。我们的基础类还存在一些棘手的问题,我们开发了一个新的 API 来解决这些问题。到目前为止,这是一次正常的、尽管影响广泛的更新。

我们的层次结构是:

  1. ASP.NET (aspx)
  2. 业务逻辑 (DLL)
  3. 基础类 (DLL)

因此 ASP.NET 不会出错,某些 DLL(特别是基础类)具有包含旧命名空间的重定向层/functions 并将它们转发到新的 API。当我们替换 DLL 时,ASP.NET 很好地识别了它们(可能是因为它触发了重新编译)。

但预编译的应用程序则不然,即使两组 DLL 中都有相同的命名空间和类。即使文件被重命名,它也会抱怨程序集名称属性不同(这是必然的)。我知道您可以重定向到同一程序集的不同版本,但是有什么方法可以重定向到完全不同的程序集吗?

替代方案是重新编译应用程序(实际上不想这样做,因为应用程序本身没有更改)或使用引用新基础 DLL 的存根重新编译旧的基础 DLL(新的虚拟 DLL 是文件系统的混乱)。

I have a question about how the .NET framework (2.0) resolves dependent assemblies.

We're currently involved in a bit of a rewrite of a large ASP.NET application and various satellite executables. There are also some nagging problems with our foundation classes that we developed a new API to solve. So far this is a normal, albeit wide-reaching, update.

Our heirarchy is:

  1. ASP.NET (aspx)
  2. business logic (DLLs)
  3. foundation classes (DLLs)

So ASP.NET doesn't throw a fit, some of the DLLs (specifically the foundation classes) have a redirection layer that contains the old namespaces/functions and forwards them to the new API. When we replaced the DLLs, ASP.NET picked them up fine (probably because it triggered a recompile).

Precompiled applications don't though, even though the same namespaces and classes are in both sets of DLLs. Even when the file is renamed, it complains about the assemblyname attribute being different (which it has to be by necessity). I know you can redirect to differnet versions of the same assembly, but is there any way to direct to a completely different assembly?

The alternatives are to recompile the applications (don't really want to because the applications themselves haven't changed) or recompile the old foundation DLL with stubs refering to the new foundation DLL (the new dummy DLL is file system clutter).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半﹌身腐败 2024-09-04 05:08:35

您想将类型移至新装配体吗?您可以使用[TypeForwardedTo(..)]来做到这一点。

如果您最初有 (AssemblyA):

namespace SomeNamespace {
    public class SomeType {}
}

您可以将该类型移至 AssemblyB 中,并拥有一个引用 AssemblyB 的几乎空的 AssemblyA 并且简单地包含:

[assembly: TypeForwardedTo(typeof(SomeNamespace.SomeType))]

然后尝试从 AssemblyA 加载 SomeNamespace.SomeType 的任何内容实际上都会从 AssemblyB 获取类型代码>.

大多数运行时都遵循此属性...除了 WCF 扩展之外的所有内容。这让我很恼火;-p 哦,它不喜欢嵌套类型......

You want to move the types to a new assembly? You can do that with [TypeForwardedTo(..)].

If you originally have (AssemblyA):

namespace SomeNamespace {
    public class SomeType {}
}

You can instead move that type into AssemblyB, and have a virtually empty AssemblyA which references AssemblyB and simply contains:

[assembly: TypeForwardedTo(typeof(SomeNamespace.SomeType))]

Then anything trying to load SomeNamespace.SomeType from AssemblyA actually gets the type from AssemblyB.

Most of the runtime respects this attribute... everything except WCF extensions. Which bit me ;-p Oh, and it isn't a fan of nested types...

浅语花开 2024-09-04 05:08:35
//File: RKAPPLET.EXE
namespace RKAPPLET
{
  using RKMFC;
  public static class Program
  {
    public static void Main ()
    {
      RKMFC.API.DoSomething();
    }
  }
}

//File: RKMFC.DLL
namespace RKMFC
{
  public static class API
  {
    public static void DoSomething ()
    {
      System.Windows.Forms.MessageBox.Show("MFC!")
    }
  }
}

//File: RKNET.DLL
namespace RKNET
{
  public static class API
  {
    public static void DoSomethingElse ()
    {
      System.Windows.Forms.MessageBox.Show("NET!")
    }
  }
}
namespace RKMFC
{
  public static class API
  {
    public static void DoSomething ()
    {
      RKNET.API.DoSomethingElse()
    }
  }
}

我希望使用 RKMFC.DLL 编译的 RKAPPLET.EXE 能够找到 RKNET.DLL(其中包含 RKMFC.DLL 中所有内容的副本,然后是一些),而无需重新编译 RKAPPLET.EXE(指向它)或 RKMFC.DLL(指向它)重定向类型)。

//File: RKAPPLET.EXE
namespace RKAPPLET
{
  using RKMFC;
  public static class Program
  {
    public static void Main ()
    {
      RKMFC.API.DoSomething();
    }
  }
}

//File: RKMFC.DLL
namespace RKMFC
{
  public static class API
  {
    public static void DoSomething ()
    {
      System.Windows.Forms.MessageBox.Show("MFC!")
    }
  }
}

//File: RKNET.DLL
namespace RKNET
{
  public static class API
  {
    public static void DoSomethingElse ()
    {
      System.Windows.Forms.MessageBox.Show("NET!")
    }
  }
}
namespace RKMFC
{
  public static class API
  {
    public static void DoSomething ()
    {
      RKNET.API.DoSomethingElse()
    }
  }
}

I want RKAPPLET.EXE, compiled with RKMFC.DLL, to find RKNET.DLL (which has a copy of everything in RKMFC.DLL and then some) without recompiling either RKAPPLET.EXE (to point to it) or RKMFC.DLL (to redirect types).

讽刺将军 2024-09-04 05:08:35

您是否尝试将 设置添加到配置文件?

http://msdn.microsoft.com/en-us/library/twy1dw1e.aspx

Did you try adding <assemblyBinding> setting to config file ?

http://msdn.microsoft.com/en-us/library/twy1dw1e.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文