在没有\Bin或GAC的ASP.NET中引用DLL [英] Reference DLLs in ASP.NET without \Bin or GAC

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

问题描述

我有一个ASP.NET项目源代码控制(Subversion)。由于各种原因,我不想将\Bin目录或其内容添加到源代码控制,所以我有svn:被忽略。在Visual Studio构建期间将DLL加载到这里,我可以从一个干净的目录开始,和/或删除该目录的所有内容,并且仍然有一个成功的构建。



有两种方法可以引用包含在项目中的代码:


  1. 在Web.config元素//配置/ configSections /系统名.web /汇编/组件。我可以 < add> GAC中的任何DLL都是这样的。我对所有的系统DLL进行此操作。

  2. 在VS解决方案中,有一个设置在 Project / ProjectSection / ProjectReferences ,让我指定包含对解决方案中其他项目的引用。

(请注意,这与非Web项目不同,其中所有对外部依赖关系的引用存储在项目文件中。VS Web项目没有项目文件,因此它们必须存储在别的地方。)



现在我有一个第三方编译的DLL,我想包括在项目中。不幸的是,我发现没有一个引用选项似乎适用于我:


  1. 通过web.config / system.web / compilation引用/ assembly不起作用,除非DLL存在于GAC中;您不能使用文件路径。我真的希望避免GAC依赖,因为这将意味着使项目在每个目标机器上工作的额外步骤。

  2. 我没有找到一种方法来包含文件引用在解决方案中,我可以使用项目引用。

  3. 每当我使用VS的添加引用对话框添加文件引用时,它只将DLL复制到\Bin目录。这对我来说不起作用,因为我的\Bin目录不是跨系统持续的。

有另一种方法可以做引用一个DLL文件并粘贴?

解决方案

如果你正在做任何一种认真的开发,我会建议迁移从网站项目和Web项目,这允许您以整个解决方案以相同的方式管理这些依赖关系。



但是,假设您不能将所有需要从Web项目引用的程序集放入某个位置的文件夹(例如lib \web),并将您的Web项目添加一个预构建事件,将该文件夹的内容复制到网路目录。现在每当你想添加一个依赖关系到你的Web项目,你可以把它放在lib \web文件夹,并添加引用。无论何时构建,所有引用的程序集都将被复制到该文件夹​​中,以便您可以删除bin文件夹或执行一个干净的签出,没有任何问题。


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. 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.

(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.)

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. Referencing via web.config/system.web/compilation/assemblies doesn't work unless the DLL exists in the GAC; you can't use a file path. I'd really like to avoid a GAC dependency as it will mean an extra step to make the project work on every target machine.
  2. I haven't found a way to include a file reference in the solution like I can do with project references.
  3. Any time I add a file reference using VS's "Add Reference" dialog, it merely copies the DLL to the \Bin directory. That won't work for me as my \Bin directory isn't persistent across systems.

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

解决方案

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.

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. lib\web ) 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 lib\web 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆