使用 32 位或 64 位 dll 编译 .net 应用程序

发布于 2024-09-14 10:31:24 字数 328 浏览 4 评论 0原文

我有一个我们在工作中编写的应用程序,它使用 SVN 的 SharpSVN 包装器。在过去的几年里,它为我们提供了很好的帮助。然而,我们已经开始引入 64 位系统,我们的应用程序似乎无法访问这些系统上的 SharpSVN dll。

我已经下载了 SharpSVN dll 的 64 位版本,我想知道下一步该怎么做。我无法阻止 32 位用户使用该应用程序,因此我需要能够针对两个平台进行编译。幸运的是,通过这个应用程序,我们将 ntier 堆栈的不同层拆分为解决方案中的单独项目,因此我使用 SharpSVN dll 的业务层是独立的。

我将如何编译应用程序的 32 位和 64 位版本,而无需维护项目的两个副本?

I have an application that we wrote here at work that uses the SharpSVN wrapper for SVN. It has served us well of the past few years. However, we have started bringing in 64-bit systems and our application cannot seem to access the SharpSVN dll on these systems.

I have downloaded the 64-bit version of the SharpSVN dll and I am wondering what to do next. I cannot stop my 32-bit users from using the application, so I need to be able to compile for both platforms. Luckily, with this application, we split different layers of the ntier stack into separate projects within the solution so my business layer that utilizes the SharpSVN dll is on its own.

How would I go about compiling both a 32-bit and 64-bit version of my application without having to maintain two copies of the project?

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

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

发布评论

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

评论(2

彩虹直至黑白 2024-09-21 10:31:24

使用 x86 平台(而不是任何 CPU)构建您的工具,即使在 64 位系统上,它也将作为 x86 代码加载。

或者您可以执行类似

class SharpSvn64 {
    [DllImport("sharpsvn64.dll")] extern public static void DoSomething();
}

class SharpSvn32 {
    [DllImport("sharpsvn32.dll")] extern public static void DoSomething();
}

class SharpSvn {
    static readonly bool Is64 = (IntPtr.Size == 8);

    void DoSomething() {
        if (Is64)
            SharpSvn64.DoSomething();
        else
            SharpSvn32.DoSomething();
    }
}

编辑:的操作,因为 SharpSVN 是托管的,所以 PInvoke 不是答案,因此构建 x86 可执行文件可能是一种方法。或者,如果接口相同,您可以订阅 AddDomain.AssemblyResolve 事件并选择您想要的程序集。不过,我不知道这是否是一个好主意。

Build your tool using the x86 platform (as opposed to Any CPU), and it will be loaded as x86 code even on 64-bit systems.

Or you can do something like

class SharpSvn64 {
    [DllImport("sharpsvn64.dll")] extern public static void DoSomething();
}

class SharpSvn32 {
    [DllImport("sharpsvn32.dll")] extern public static void DoSomething();
}

class SharpSvn {
    static readonly bool Is64 = (IntPtr.Size == 8);

    void DoSomething() {
        if (Is64)
            SharpSvn64.DoSomething();
        else
            SharpSvn32.DoSomething();
    }
}

Edit: Since SharpSVN is managed, PInvoke wouldn't be the answer, so building x86 executables are probably the way. Or, if the interface is identical, you MAY get away with subscribing to the AddDomain.AssemblyResolve event and choose which assembly you want in that. I don't know if this is a good idea, though.

奶茶白久 2024-09-21 10:31:24

从描述来看,您的 vb.net 应用程序似乎是使用 Any CPU 选项构建的,这意味着它将作为 64 位应用程序在 64 位计算机上运行。在这种情况下,它不会加载 32 位 DLL。

您应该能够将其更改为以 32 位运行,而不是尝试同时使用 32 位和 64 位版本。部署更简单。在项目属性构建选项卡下,选择 x86

From the description, it sounds like your vb.net application is built with the Any CPU option, which means it would run as a 64-bit application on a 64-bit machine. In that case, it would not load the 32-bit DLL.

Rather than try to use both a 32-bit and 64-bit version, you should be able to just change it to run as 32-bit. Simpler deployment. Under the project properties build tab, choose x86.

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