ASP.NET 如何找到我的类库?

发布于 2024-12-06 04:59:55 字数 1285 浏览 2 评论 0原文

我被要求更新其他人创建的 ASP.NET 应用程序正在使用的类库 DLL。但是,当我查看 ASP.NET 应用程序的文件夹结构时,我发现该 DLL 存在于两个不同的文件夹下,并且看起来该应用程序在第一次运行时使用一个 DLL,但在重新启动 IIS 后使用另一个 DLL。我计划修复问题,以便 DLL 在应用程序中仅存在一次,但我想首先了解发生了什么。

事情是这样的 - 该 DLL 名为 MyLib.DLL,它存在于 BIN 子文件夹和名为 MyLibrary 的文件夹中。下面是应用程序中的 ASPX 页面如何调用类库中的方法的示例:

Dim oMyClass As New MyLib.MyClass
Dim sTemp As String = oMyClass.GetVersion()

应用程序的 web.config 文件中也有此部分:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="MyLib" culture="neutral"/>
      <codeBase version="1.0.0.0" href="MyLibrary/MyLib.dll"/>
    </dependentAssembly>
  </assemblyBinding>
</runtime>

由于应用程序有两个不同的 MyLib.DLL 副本,因此我更新了两者并拥有GetVersion 函数返回不同的结果,因此我可以知道正在使用哪个 DLL。当我第一次运行该应用程序时,我可以看到 ASP.NET 正在“Temporary ASP.NET Files”文件夹下创建一个文件夹,并生成 MyLib.DLL 的 BIN 版本的副本。当调用 GetVersion 函数时,应用程序将返回“来自 BIN 文件夹”。但是,如果我重新启动 IIS 并再次运行该应用程序,GetVersion 将开始返回“来自 MyLibrary 文件夹”,表明它现在使用的是 MyLibrary 文件夹而不是 BIN 文件夹中的 DLL。

那么,为什么 ASP.NET 首先使用 DLL 的 BIN 版本,然后在 IIS 重新启动后使用代码库设置中指定的版本呢?如果我想摆脱 BIN 版本的 DLL,如何将应用程序配置为仅使用 MyLibrary 文件夹中的副本?我尝试删除 BIN 版本,但应用程序给了我一个错误,指出无法找到程序集。

谢谢 - 我是 ASP.NET 新手,所以我希望这个问题有意义。

I have been asked to update a class library DLL that is being used by an ASP.NET application that someone else created. However, when I looked at the folder structure for the ASP.NET app, I found that the DLL existed under two different folders, and it looks like the app uses one DLL when you first run it, but the other after you restart IIS. I plan on fixing things up so the DLL only exists once in the application, but I'd like to understand what is happening first.

Here's the deal - the DLL is called MyLib.DLL and it exists in both a BIN subfolder and a folder called MyLibrary. Here's an example of how an ASPX page in the app calls a method in the class library:

Dim oMyClass As New MyLib.MyClass
Dim sTemp As String = oMyClass.GetVersion()

The application also has this section in the web.config file:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="MyLib" culture="neutral"/>
      <codeBase version="1.0.0.0" href="MyLibrary/MyLib.dll"/>
    </dependentAssembly>
  </assemblyBinding>
</runtime>

Since the app had two different copies of MyLib.DLL, I updated both and had the GetVersion function return different results so I could tell which DLL was being used. When I run the app for the very first time, I can see that ASP.NET is creating a folder under the "Temporary ASP.NET Files" folder and it makes a copy of the BIN version of MyLib.DLL. And the app will return "From BIN folder" when calling the GetVersion function. However, if I restart IIS and run the app again, GetVersion will start returning "From MyLibrary folder", indicating that it is now using the DLL from the MyLibrary folder rather than the BIN folder.

So, why is ASP.NET using the BIN version of the DLL first, but then using the one specified in the Codebase setting after a restart of IIS? If I wanted to get rid of the BIN version of the DLL, how can I configure the application to only use the copy in the MyLibrary folder? I tried getting rid of the BIN version, but then the app gave me an error that the assembly could not be found.

Thanks - I'm new to ASP.NET so I hope this question made sense.

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

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

发布评论

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

评论(1

来世叙缘 2024-12-13 04:59:55

您是否尝试过删除指向 MyLibrary 目录的 dependentAssembly 调用?就我个人而言,我认为使用 bin 目录更有意义,因为它是标准做法,不需要额外的配置。

Have you tried just removing the dependentAssembly call that's pointing to the MyLibrary directory? Personally, I think it makes more sense to use the bin directory since it's standard practice and no additional configuration is necessary.

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