代码之家  ›  专栏  ›  技术社区  ›  Khaled Musaied

强制ASP.NET应用程序从bin而不是GAC加载程序集

  •  16
  • Khaled Musaied  · 技术社区  · 17 年前

    我无法删除gac版本,因为其他应用程序正在使用它,并且我在向gac添加新版本时遇到了一些困难。

    8 回复  |  直到 17 年前
        1
  •  8
  •   Khaled Musaied    17 年前

    我找到了

    要强制应用程序从本地bin目录读取,必须从程序集中删除签名,然后应用程序将从bin加载程序集。

        2
  •  5
  •   Abel    10 年前

    更改版本号,强名称程序集,并引用您在解决方案中部署的强名称更高版本。

        3
  •  2
  •   Paco Zarate    13 年前

    Muse VSExtensions建议的旧版本配置有效!您可以为本地程序集使用强名称: http://msdn.microsoft.com/en-us/library/7wd6ex19.aspx

    基本上,在web.config中添加如下内容:

      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="DllName"
              publicKeyToken="0123456789abc"
              culture="neutral" />        
            <!-- Assembly versions can be redirected in app, 
              publisher policy, or machine configuration files. -->
            <bindingRedirect oldVersion="2.0.0.0-2.5.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>      
        </assemblyBinding>  
      </runtime>
    

    这样,如果gac中有一个可以从版本2.0.0.0到版本2.5.0.0的程序集,所有调用都将重定向到新版本(3.0.0.0)

    在“装配”部分,我添加了装配:

    <add assembly="DllName, Version=3.0.0.0, Culture=neutral, PublicKeyToken=0123456789abc" />
    

    就这样。

        4
  •  2
  •   Community Mohan Dere    9 年前

    作为建议解决方案的替代方案,在开发过程中,您可以通过设置 DEVPATH environment variable 使能 Development Mode machine.config . 我认为这是迄今为止实现您想要的最简单的方法,但不应用于生产。

    bindingRedirect 一些用户在这里提到的方法。

    首先,将以下内容添加到 machine.config :

    <configuration>
      <runtime>
        <developmentMode developerInstallation="true"/>
      </runtime>
    </configuration>
    

    然后,设置 DEVPATH 环境变量设置为非签名程序集的位置。这将迫使Fusion的DEVOVERRIDE模式启动并搜索 DEVPATH (及其子目录)在探测GAC之前。

    An FAQ of DEVPATH and DEVOVERRIDE on MSDN 将回答有关使用此功能效果的大多数问题。

    DEVPATH Fusion Log Viewer (fuslogvw) 要查看您是否正确启用了它, as explained in this blog post on DEVPATH

    新使用FusLogVw? Scott Hanselman wrote an excellent intro

    请注意,Fusion日志查看器(或程序集绑定日志查看器,名称中的内容)会令人困惑地说您使用了 转移 环境变量。它应该是这样的:

    LOG: Found assembly in DEVOVERRIDE path D:\testassemblies\Test.DLL
    

    DEVPATH 地点,你 should set a registry key to this location ,即设置(检查.NET版本密钥以匹配.NET版本):

    [HKEY_CURRENT_USER\
        SOFTWARE\
        Microsoft\
        .NETFramework\
        v2.0.50727\AssemblyFoldersEx\
        DEVPATH]@="C:\SharedAssemblies"
    
        5
  •  1
  •   Community Mohan Dere    9 年前

    How to prevent a .NET application from loading/referencing an assembly from the GAC?

    我猜在要求库作为程序集加载之前,对本地DLL文件调用LoadLibrary, 可以

        6
  •  0
  •   Mark Sowul    12 年前

    要将一个版本重定向到另一个版本,请使用<绑定重定向>要素oldVersion属性可以指定单个版本,也可以指定一系列版本。例如,指定运行时应使用版本2.0.0.0,而不是1.1.0.0和1.2.0.0之间的程序集版本。

    s

        7
  •  0
  •   Hung Ha    10 年前

    而不是使用 绑定重定向 代码基 路径我有一个使用MySQL.Data.dll的工作示例。

    <dependentAssembly>
        <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
        <codebase version="5.2.5.0" href="/bin/MySQL.Data.dll" />        
      </dependentAssembly>
    

        8
  •  -1
  •   Matthew    17 年前

    为什么不将您喜欢的版本安装到GAC中,然后在GAC中引用它呢?

    推荐文章