如果我在 GAC 中有两个同名的程序集,我如何告诉 .Net 使用哪个?

发布于 2024-07-08 05:08:27 字数 95 浏览 7 评论 0原文

我在全局程序集缓存中有两个同名的程序集,但版本号不同。 如何告诉我的程序要引用哪个版本?

根据记录,这是 ASP.Net 网站中的 VB.Net 页面。

I have two assemblies with the same name in the Global Assembly cache, but with different version numbers. How do I tell my program which version to reference?

For the record, this is a VB.Net page in an ASP.Net web site.

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

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

发布评论

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

评论(4

愚人国度 2024-07-15 05:08:27

将程序集添加到配置文件的 程序集 部分下并包含版本号。

<configuration>
   <system.web>
      <compilation>
         <assemblies>
            <add assembly="System.Data, Version=1.0.2411.0, 
                           Culture=neutral, 
                           PublicKeyToken=b77a5c561934e089"/>
         </assemblies>
      </compilation>
   </system.web>
</configuration>

add 元素添加在动态资源编译期间使用的程序集引用。 编译每个代码模块时,ASP.NET 会自动将此程序集链接到资源。

Add the assembly to the config file under the assemblies section with version number.

<configuration>
   <system.web>
      <compilation>
         <assemblies>
            <add assembly="System.Data, Version=1.0.2411.0, 
                           Culture=neutral, 
                           PublicKeyToken=b77a5c561934e089"/>
         </assemblies>
      </compilation>
   </system.web>
</configuration>

The add element adds an assembly reference to use during compilation of a dynamic resource. ASP.NET automatically links this assembly to the resource when compiling each code module.

胡渣熟男 2024-07-15 05:08:27

只要版本号不同(这是必需的),您就可以通过 web.config 文件指定正确的版本。 这就是我在我的一个应用程序中进行设置以引用正确版本的 Crystal Reports 的方式,因为我们在 GAC 中有多个版本:

<system.web>

   <compilation>
         <assemblies>
            <add assembly="CrystalDecisions.Web, Version=11.5.3700.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
            <add assembly="CrystalDecisions.Shared, Version=11.5.3700.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
            <add assembly="CrystalDecisions.ReportSource, Version=11.5.3700.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
            <add assembly="CrystalDecisions.Enterprise.Framework, Version=11.5.3300.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
         </assemblies>
      </compilation>

</system.web>

As long as the version number is different (which would be required), you can specify the proper version through your web.config file. This is how I have things setup in one of my apps to reference the proper version of Crystal Reports, since we have multiple versions in the GAC:

<system.web>

   <compilation>
         <assemblies>
            <add assembly="CrystalDecisions.Web, Version=11.5.3700.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
            <add assembly="CrystalDecisions.Shared, Version=11.5.3700.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
            <add assembly="CrystalDecisions.ReportSource, Version=11.5.3700.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
            <add assembly="CrystalDecisions.Enterprise.Framework, Version=11.5.3300.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
         </assemblies>
      </compilation>

</system.web>
后知后觉 2024-07-15 05:08:27

当您在配置文件中添加对 DLL 的引用时,您可以指定版本以及强名称:

<add assembly="Foo.Bar, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>

<add assembly="Foo.Bar, Version=2.5.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>

When you add a reference to the DLL in your config file, you specify the version as well as the strong name:

<add assembly="Foo.Bar, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>

or

<add assembly="Foo.Bar, Version=2.5.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
能否归途做我良人 2024-07-15 05:08:27

要在 GAC 中安装程序集,您必须为其指定一个强名称。 强名字永远不会重复。 因此,要指定要使用哪个程序集,请通过强名称引用它。

To install an assembly in the GAC you have to give it a strong name. Strong names are never duplicated. So to specify which assembly you want to use you reference it by the strong name.

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