如何在ASP.net应用程序中引用bin文件夹之外的程序集?

时间:2023-01-13 11:13:23

I've a working XML Web service written in ASP.Net. Now I need to reference certain assemblies lying in a specific folder e.g. c:\NotMyCode
I do not want to copy/duplicate zillions of dlls in that folder into my bin folder.

我有一个用ASP.Net编写的工作XML Web服务。现在我需要引用位于特定文件夹中的某些程序集,例如c:\ NotMyCode我不想将该文件夹中的数百万个dll复制/复制到我的bin文件夹中。

I tried to keep the CopyLocal=false for the assemblies referred in the Web Service. That ended up in a FileNotFound exception for the assembly. When I switch to CopyLocal=true, the referenced DLLs are copied over to the bin folder.. and it works.

我试图保持Web服务中引用的程序集的CopyLocal = false。最终导致程序集的FileNotFound异常。当我切换到CopyLocal = true时,引用的DLL被复制到bin文件夹..它的工作原理。

So my question here is: How do I reference assemblies that do not lie in my bin folder or a subfolder beneath it ? Do I need to change some security policy files somewhere? I think I'm not the first person to ever want to do something like this.. so I'm assuming someone has already solved this problem.

所以我的问题是:如何引用不在我的bin文件夹或它下面的子文件夹中的程序集?我是否需要在某处更改某些安全策略文件?我想我不是第一个想做这样事情的人......所以我假设有人已经解决了这个问题。

(I've tried impersonating an admin user in the IIS ASP.net configuration panel, but that didnt work either.)

(我已经尝试在IIS ASP.net配置面板中模拟管理员用户,但这也没有用。)

Update: Can't install it in the GAC either. To give an analogy, this web service is giving a simplified view to a third party app e.g. Starteam. I can't (shouldn't have to.. don't want to..) copy all the binaries in that folder to the bin folder or install it into the GAC

更新:无法将其安装在GAC中。举一个类比,这个网络服务给第三方应用程序提供了一个简化的视图,例如StarTeam中。我不能(不应该......不想......)将该文件夹中的所有二进制文件复制到bin文件夹或将其安装到GAC中

5 个解决方案

#1


14  

According to the MSDN documentation,

根据MSDN文档,

Referenced assemblies outside the application's root directory must have strong names and must either be installed in the global assembly cache or specified using the <codeBase> element.

应用程序根目录外部的引用程序集必须具有强名称,并且必须安装在全局程序集缓存中或使用 元素指定。

So, it might appear that you're out of luck. Here's what I'd try:

所以,看起来你运气不好。这是我尝试的:

  1. Create an NTFS junction point under your application base directory which points to the directory containing your shared code. This is the key step. For example, in your application base directory, run linkd SharedCode c:\NotMyCode. This makes <yourappbase>\SharedCode effectively be an alias for c:\NotMyCode.
  2. 在应用程序基目录下创建一个NTFS交接点,该目录指向包含共享代码的目录。这是关键的一步。例如,在应用程序基目录中,运行链接的SharedCode c:\ NotMyCode。这使得 \ SharedCode有效地成为c:\ NotMyCode的别名。
  3. Tell ASP.NET to probe for assemblies in this path, using a <probing> element, referencing the junction point SharedCode. Since this is under your application base, it should work. Alternatively, use AppDomainSetup.PrivateBinPath to set the path probed for assemblies.
  4. 告诉ASP.NET使用 元素探测此路径中的程序集,引用连接点SharedCode。由于这是在您的应用程序基础之下,它应该工作。或者,使用AppDomainSetup.PrivateBinPath设置探测程序集的路径。

I'm quite curious to see if this works :-)

我很好奇,看看这是否有效:-)

#2


4  

You could always use the: AppDomain.CurrentDomain.AssemblyResolve Event and call

您始终可以使用:AppDomain.CurrentDomain.AssemblyResolve事件并调用

Assemly.Load(Path.Combine(@"c:\NotMyStuff",args.Name.Substring(0, args.Name.IndexOf(",")) + ".dll"))

See link for more info.

有关详细信息,请参阅链接

#3


0  

You could always put your referenced assemblies in the GAC, then the location would not matter. You can install the component by dragging it into the GAC (C:\windows\assembly) or running GACUtil.exe.

您始终可以将引用的程序集放在GAC中,然后位置无关紧要。您可以通过将组件拖入GAC(C:\ windows \ assembly)或运行GACUtil.exe来安装该组件。

This article may help. It describes the "Best Practices for Assembly Loading."

这篇文章可能有帮助。它描述了“装配装载的最佳实践”。

At first I thought you could used the <probing privatePath="bin\debug"/> element in the runtime/assemblyBinding in the web.config, but the probing will only allow you to specify subdirectories under the root location.

起初我以为你可以在web.config中的runtime / assemblyBinding中使用 元素,但是探测只允许你在根位置下指定子目录。

#4


0  

I think you can reference specific assembly paths in code as well.

我想你也可以在代码中引用特定的汇编路径。

AppDomain.CurrentDomain.AppendPrivatePath("C:\\NotMyCode");

Doing that in your Global.asax Application_Start should do the trick.

在Global.asax Application_Start中执行此操作应该可以解决问题。

#5


-1  

You can put in GAC and access it from there.

您可以放入GAC并从那里访问它。

#1


14  

According to the MSDN documentation,

根据MSDN文档,

Referenced assemblies outside the application's root directory must have strong names and must either be installed in the global assembly cache or specified using the <codeBase> element.

应用程序根目录外部的引用程序集必须具有强名称,并且必须安装在全局程序集缓存中或使用 元素指定。

So, it might appear that you're out of luck. Here's what I'd try:

所以,看起来你运气不好。这是我尝试的:

  1. Create an NTFS junction point under your application base directory which points to the directory containing your shared code. This is the key step. For example, in your application base directory, run linkd SharedCode c:\NotMyCode. This makes <yourappbase>\SharedCode effectively be an alias for c:\NotMyCode.
  2. 在应用程序基目录下创建一个NTFS交接点,该目录指向包含共享代码的目录。这是关键的一步。例如,在应用程序基目录中,运行链接的SharedCode c:\ NotMyCode。这使得 \ SharedCode有效地成为c:\ NotMyCode的别名。
  3. Tell ASP.NET to probe for assemblies in this path, using a <probing> element, referencing the junction point SharedCode. Since this is under your application base, it should work. Alternatively, use AppDomainSetup.PrivateBinPath to set the path probed for assemblies.
  4. 告诉ASP.NET使用 元素探测此路径中的程序集,引用连接点SharedCode。由于这是在您的应用程序基础之下,它应该工作。或者,使用AppDomainSetup.PrivateBinPath设置探测程序集的路径。

I'm quite curious to see if this works :-)

我很好奇,看看这是否有效:-)

#2


4  

You could always use the: AppDomain.CurrentDomain.AssemblyResolve Event and call

您始终可以使用:AppDomain.CurrentDomain.AssemblyResolve事件并调用

Assemly.Load(Path.Combine(@"c:\NotMyStuff",args.Name.Substring(0, args.Name.IndexOf(",")) + ".dll"))

See link for more info.

有关详细信息,请参阅链接

#3


0  

You could always put your referenced assemblies in the GAC, then the location would not matter. You can install the component by dragging it into the GAC (C:\windows\assembly) or running GACUtil.exe.

您始终可以将引用的程序集放在GAC中,然后位置无关紧要。您可以通过将组件拖入GAC(C:\ windows \ assembly)或运行GACUtil.exe来安装该组件。

This article may help. It describes the "Best Practices for Assembly Loading."

这篇文章可能有帮助。它描述了“装配装载的最佳实践”。

At first I thought you could used the <probing privatePath="bin\debug"/> element in the runtime/assemblyBinding in the web.config, but the probing will only allow you to specify subdirectories under the root location.

起初我以为你可以在web.config中的runtime / assemblyBinding中使用 元素,但是探测只允许你在根位置下指定子目录。

#4


0  

I think you can reference specific assembly paths in code as well.

我想你也可以在代码中引用特定的汇编路径。

AppDomain.CurrentDomain.AppendPrivatePath("C:\\NotMyCode");

Doing that in your Global.asax Application_Start should do the trick.

在Global.asax Application_Start中执行此操作应该可以解决问题。

#5


-1  

You can put in GAC and access it from there.

您可以放入GAC并从那里访问它。