本文介绍了在没有 Bin 或 GAC 的情况下在 ASP.NET 中引用 DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个受源代码控制 (Subversion) 的 ASP.NET 项目.由于各种原因,我不想将 Bin 目录或其内容添加到源代码管理中,因此我将其设置为 svn:ignored.DLL 在 Visual Studio 构建期间加载到此处,我可以从一个干净的目录开始和/或删除该目录的所有内容,并且仍然可以成功构建.

I have an ASP.NET project under source control (Subversion). For various reasons, I don't want to add the Bin directory or its contents to source control, so I have it svn:ignored. DLLs are loaded into here during a Visual Studio build, and I can start with a clean directory and/or delete all the contents of this directory and still have a successful build.

我有两种方式引用代码以包含在项目中:

There are two ways that I reference code for inclusion in the project:

  1. 在 Web.config 元素中//configuration/configSections/system.web/compilation/assemblies.我可以任何DLL这是在 GAC 中的这种方式.我为所有系统 dll 执行此操作.
  2. 在 VS 解决方案中,Project/ProjectSection/ProjectReferences 中有一个设置a> 允许我指定对解决方案中其他项目的引用.
  1. In the Web.config element //configuration/configSections/system.web/compilation/assemblies. I can <add> any DLL that's in the GAC this way. I do this for all of the System dlls.
  2. In the VS Solution, there's a setting at Project/ProjectSection/ProjectReferences that lets me specify included references to other projects in the solution.

(请注意,这与非 Web 项目不同,其中对外部依赖项的所有引用都存储在项目文件中.VS Web 项目没有项目文件,因此必须将它们存储在某处否则.)

(Note that this is different than non-web projects, where all references to external dependencies are stored in the project file. There's no project file for VS web projects so they have to be stored somewhere else.)

现在我有一个 3rd-party 编译的 DLL,我想将它包含在项目中.不幸的是,我发现的所有引用选项似乎都不适合我:

Now I have a 3rd-party compiled DLL that I'd like to include in the project. Unfortunately, none of the referencing options I've found seem to work for me:

  1. 除非 DLL 存在于 GAC 中,否则无法通过 web.config/system.web/compilation/assemblies 进行引用;你不能使用文件路径.我真的很想避免 GAC 依赖,因为这意味着要使项目在每台目标机器上都能正常运行需要一个额外的步骤.
  2. 我还没有找到像处理项目引用那样在解决方案中包含文件引用的方法.
  3. 每当我使用 VS 的添加引用"对话框添加文件引用时,它只会将 DLL 复制到 Bin 目录中.这对我不起作用,因为我的 Bin 目录不是跨系统持久的.

还有其他方法可以引用 DLL 文件并将其保留吗?

Is there another way I can make a reference to a DLL file and have it stick?

推荐答案

如果您正在进行任何类型的严肃开发,我建议您从网站项目迁移到 Web 项目,因为这允许您管理这些类型的在整个解决方案中以相同的方式依赖.

If you are doing any kind of serious development I would recommend migrating away from the web site project and to a web project as this allows you to manage these kind of dependencies in the same manner across your entire solution.

但是,假设您不能这样做,请将您需要从 Web 项目中引用的所有程序集放入某个文件夹中(例如 libweb ),并向您的 Web 项目添加一个预构建事件以复制内容将该文件夹复制到 web 目录的 bin 文件夹中.现在,无论何时您想向 Web 项目添加依赖项,您都可以将其放到 libweb 文件夹中,然后添加引用.每当您构建时,所有引用的程序集都将复制到该文件夹​​中,因此您可以删除 bin 文件夹或进行干净的检出而不会出现任何问题.

However, assuming you cannot do that, place all of the assemblies that you need to reference from the web project into a folder somewhere ( e.g. libweb ) and add a pre-build event to your web project that copies the content of that folder into the bin folder of the web directory. Now whenever you want to add a dependency to your web project you can drop it in the libweb folder, and add the reference. Whenever you build, all of the referenced assemblies will be copied into the folder so you can delete the bin folder or do a clean checkout and not have any issue.

这篇关于在没有 Bin 或 GAC 的情况下在 ASP.NET 中引用 DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 02:35