从/bin而不是GAC加载程序集?

时间:2021-01-09 02:46:49

I have two assemblies, created through conditional compilation (dev and real).

我有两个程序集,通过条件编译(dev和real)创建。

The public surface of these assemblies is 100% identical: both are strongly named; both are signed with the same .snk and therefore have the same PublicKeyToken; both have the same culture and the same version. I cannot change this: making them appear identical is the whole point.

这些程序集的公共表面100%相同:它们都被强命名;两者都使用相同的.snk签名,因此具有相同的PublicKeyToken;两者都有相同的文化和版本。我无法改变这一点:让它们看起来完全相同是关键。

However, on my machine the real assembly is in the GAC. I have an ASP.NET 3.5 WebForms app that references the dev assembly. It absolutely must do that; the real assembly crashes the app.

然而,在我的机器上,真正的组装是在GAC。我有一个ASP。NET 3.5 WebForms应用程序引用开发程序集。它必须这样做;真正的程序集崩溃了。

Is there a way to force a specific ASP.NET application to use the dev one (which is in /bin), given that:

有没有办法强制一个特定的ASP。NET应用程序使用dev one(在/bin中),假定:

  • There is one in the GAC.
  • GAC里面有一个。
  • Both have the same Version and PublicKeyToken.
  • 两者都有相同的版本和PublicKeyToken。
  • Both are strongly named/signed with the same key.
  • 它们都用相同的键进行强命名/签名。
  • I can not change them, can't change the version, and can't remove the key.
  • 我不能更改它们,不能更改版本,也不能删除密钥。

I noticed that someone already asked this in #991293, but the accepted answer involved removing the signing, which isn't an option here.

我注意到有些人在#991293中已经问过这个问题,但是公认的答案是删除签名,这在这里不是一个选项。

Am I out of luck?

我运气不好吗?

5 个解决方案

#1


12  

GAC is always tried first, when binding assemblies: How the Runtime Locates Assemblies

当绑定程序集:运行时如何定位程序集时,总是首先尝试GAC

So no, you can't do this. However if you explain why you have such strange requirements there might be a different work around, you have not thought of.

不,你不能这么做。然而,如果你解释了为什么你会有这样奇怪的要求,可能会有不同的工作,你没有想到。

#2


12  

No there is no way to do this. When loading an assembly the CLR will check to see if a DLL with an equivalent strong name is present in the GAC. If there is a matching assembly in the GAC it will pick the GAC assembly every time. There is unfortunately no way to override this behavior.

不,没有办法这么做。加载程序集时,CLR将检查GAC中是否存在具有等效强名称的DLL。如果GAC中有一个匹配的程序集,它将每次选择GAC程序集。不幸的是,没有办法推翻这种行为。

#3


3  

It is possible, but it is advanced and require your knownledge on CLR and how it works and C++.

这是可能的,但它是高级的,需要你知道关于CLR以及它是如何工作和c++的。

Take a look at this google book:Customizing the Microsoft® .NET Framework Common Language Runtime

看看这个google图书:定制Microsoft®. net框架公共语言运行时

Keywords: IHostAssemblyManager, IHostAssemblyStore

关键词:IHostAssemblyManager IHostAssemblyStore

#4


1  

I found another way. It is only meant for developers, but it works. According to https://msdn.microsoft.com/en-us/library/cskzh7h6(v=vs.100).aspx you set this in the your .config file

我发现的另一种方式。它只适用于开发人员,但它确实有效。根据https://msdn.microsoft.com/en-us/library/cskzh7h6(v=vs.100)

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

You also need to set the Environment variable DEVPATH with to the path of your dll. Open a cmd, set the variable, run your app:

还需要将环境变量DEVPATH设置为dll的路径。打开cmd,设置变量,运行app:

SET DEVPATH=YOURLOCALPATH

This helped me to load a local Oracle.ManagedDataAccess.dll since Oracle releases new versions, but they all have the same Version and PublicKeyToken. Thanks Oracle!

这帮助我加载本地orac . manageddataaccess。因为Oracle发布了新版本,所以它们都有相同的版本和PublicKeyToken。由于甲骨文!

You can use Process Explorer from Microsoft to see the difference. See https://technet.microsoft.com/en-us/sysinternals/ See this as a small proof of concept: 从/bin而不是GAC加载程序集?

您可以使用Microsoft的Process Explorer来查看不同之处。参见https://technet.microsoft.com/en-us/sysinternals/这是概念的一个小证明:

#5


0  

You'd have to do something like manually loading the assembly from the file (Assembly.LoadFrom, or Assembly.Load(byte[]) ) before it is loaded from the GAC, and then handle the AppDomain.AssemblyResolve event. Check out Suzanne Cook's blog post for more details.

您必须做一些事情,比如从文件(程序集)手动加载程序集。LoadFrom或Assembly.Load(byte[]))在从GAC加载之前,然后处理AppDomain。AssemblyResolve事件。看看苏珊娜·库克的博客,了解更多细节。

#1


12  

GAC is always tried first, when binding assemblies: How the Runtime Locates Assemblies

当绑定程序集:运行时如何定位程序集时,总是首先尝试GAC

So no, you can't do this. However if you explain why you have such strange requirements there might be a different work around, you have not thought of.

不,你不能这么做。然而,如果你解释了为什么你会有这样奇怪的要求,可能会有不同的工作,你没有想到。

#2


12  

No there is no way to do this. When loading an assembly the CLR will check to see if a DLL with an equivalent strong name is present in the GAC. If there is a matching assembly in the GAC it will pick the GAC assembly every time. There is unfortunately no way to override this behavior.

不,没有办法这么做。加载程序集时,CLR将检查GAC中是否存在具有等效强名称的DLL。如果GAC中有一个匹配的程序集,它将每次选择GAC程序集。不幸的是,没有办法推翻这种行为。

#3


3  

It is possible, but it is advanced and require your knownledge on CLR and how it works and C++.

这是可能的,但它是高级的,需要你知道关于CLR以及它是如何工作和c++的。

Take a look at this google book:Customizing the Microsoft® .NET Framework Common Language Runtime

看看这个google图书:定制Microsoft®. net框架公共语言运行时

Keywords: IHostAssemblyManager, IHostAssemblyStore

关键词:IHostAssemblyManager IHostAssemblyStore

#4


1  

I found another way. It is only meant for developers, but it works. According to https://msdn.microsoft.com/en-us/library/cskzh7h6(v=vs.100).aspx you set this in the your .config file

我发现的另一种方式。它只适用于开发人员,但它确实有效。根据https://msdn.microsoft.com/en-us/library/cskzh7h6(v=vs.100)

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

You also need to set the Environment variable DEVPATH with to the path of your dll. Open a cmd, set the variable, run your app:

还需要将环境变量DEVPATH设置为dll的路径。打开cmd,设置变量,运行app:

SET DEVPATH=YOURLOCALPATH

This helped me to load a local Oracle.ManagedDataAccess.dll since Oracle releases new versions, but they all have the same Version and PublicKeyToken. Thanks Oracle!

这帮助我加载本地orac . manageddataaccess。因为Oracle发布了新版本,所以它们都有相同的版本和PublicKeyToken。由于甲骨文!

You can use Process Explorer from Microsoft to see the difference. See https://technet.microsoft.com/en-us/sysinternals/ See this as a small proof of concept: 从/bin而不是GAC加载程序集?

您可以使用Microsoft的Process Explorer来查看不同之处。参见https://technet.microsoft.com/en-us/sysinternals/这是概念的一个小证明:

#5


0  

You'd have to do something like manually loading the assembly from the file (Assembly.LoadFrom, or Assembly.Load(byte[]) ) before it is loaded from the GAC, and then handle the AppDomain.AssemblyResolve event. Check out Suzanne Cook's blog post for more details.

您必须做一些事情,比如从文件(程序集)手动加载程序集。LoadFrom或Assembly.Load(byte[]))在从GAC加载之前,然后处理AppDomain。AssemblyResolve事件。看看苏珊娜·库克的博客,了解更多细节。