如何让 2 个同名的 .Net Dll 一起工作?

发布于 2024-10-07 05:30:21 字数 300 浏览 1 评论 0原文

我的应用程序中有一个 DLL,它本身可以正常工作。但是,供应商发布了该 dll 的较新版本,我尝试使用 Visual Studio 合并该 dll。这些 DLL 共享相同的文件名,但使用不同的命名空间,并且后者不向后兼容。

为了让 VS 使用较新的文件,我重命名了该文件,这是有意义的。然而,每次我构建应用程序时,它只想将较新的 dll 复制到应用程序文件夹,而基本上忽略较旧的 dll。我尝试过“复制本地”和其他设置,但没有成功。我或许可以将 dll 添加到 GAC 中并完成它,但我并不是真的想这样做。

我怎样才能让 VS 将两者视为完全独立的项目?

I have a certain DLL in my application which works fine by itself. However, the vendor released a newer version of the dll that I am attempting to incorporate using Visual Studio. The DLLs share the same filename, while using different namespaces, and the later one is not backwards compatible.

To get VS to even use the newer one I renamed the file which makes sense. However, every time I build the application it only wants to copy the newer dll to the application folder and basically ignores the older dll. I have tried 'copy local' and other settings with no luck. I could probably add the dll to the GAC and be done with it, but don't really want to.

How can I get VS to treat both as totally separate items?

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

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

发布评论

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

评论(3

漫雪独思 2024-10-14 05:30:21

我的应用程序中有一个 DLL,它本身可以正常工作。但是,供应商发布了该 dll 的较新版本,我正尝试使用 Visual Studio 合并该 dll

为什么不完全删除旧的 DLL 并更改代码以使新的 DLL 工作?为什么要同时使用两者?

I have a certain DLL in my application which works fine by itself. However, the vendor released a newer version of the dll that I am attempting to incorporate using Visual Studio

Why don't you just remove the old DLL completely and change your code to make the new one work? Why would you want to use both at the same time?

月野兔 2024-10-14 05:30:21

您可以将这两个 DLL 部署到不同的子目录。然后,您需要在 app.config 中设置规则,告诉 .NET 在哪里可以找到每个版本。

基于 MSDN 页面的 element

<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <dependentAssembly>
            <assemblyIdentity name="myAssembly"
                              publicKeyToken="32ab4ba45e0a69a1"
                              culture="neutral" />
            <codeBase version="1.0.0.0"
                      href="Version1/myAssembly.dll"/>
            <codeBase version="2.0.0.0"
                      href="Version2/myAssembly.dll"/>
         </dependentAssembly>
      </assemblyBinding>
   </runtime>
</configuration>

在构建时,您需要设置 Copy Local=false,以防止 Visual Studio 变得混乱。您还需要一个构建后步骤来设置 Version1 和 Version2 子目录。

请注意,这假设您可以根据版本号区分 DLL。

You can deploy the two DLLs to different subdirectories. You'll then need to set up rules in your app.config that tell .NET where to find each version.

An example based on the MSDN page for the <codeBase> element:

<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <dependentAssembly>
            <assemblyIdentity name="myAssembly"
                              publicKeyToken="32ab4ba45e0a69a1"
                              culture="neutral" />
            <codeBase version="1.0.0.0"
                      href="Version1/myAssembly.dll"/>
            <codeBase version="2.0.0.0"
                      href="Version2/myAssembly.dll"/>
         </dependentAssembly>
      </assemblyBinding>
   </runtime>
</configuration>

At build time you'll need to set Copy Local=false, to prevent Visual Studio from becoming confused. You'll also need a post-build step that sets up the Version1 and Version2 subdirectories.

Note that this assumes you can tell the DLLs apart based on the version number.

A君 2024-10-14 05:30:21

实际上,我通过一个简单的构建后步骤将 dll 复制到应用程序文件夹来解决了这个问题。 VS 对待每个不同,但在构建时只复制后者。

I actually solved the problem with a simple post build step to copy the dll to the application folder. VS treated each different, but at build time only copied the later.

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