为什么从海关总署,ASP.NET网站引用程序集添加本地引用时? [英] Why does ASP.NET web site reference assembly from GAC, when adding local reference?

查看:128
本文介绍了为什么从海关总署,ASP.NET网站引用程序集添加本地引用时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您使用ASP.NET网站(而不是Web应用程序模型),并添加引用从本地文件夹时,Visual Studio程序集,似乎明白这个当地组装也是GAC等不会复制该组件到bin文件夹(因为它与非GAC组件一样),而只是在web.config文件中增加了新的纪录。

When you use ASP.NET web site (instead of web application model) and add reference to an assembly from local folder, Visual Studio, it seems, understands that this local assembly is also in GAC and so does NOT copy this assembly to bin folder (as it does with non-GAC assemblies), but simply adds new record in web.config file.

为什么这样的行为?是否有可能迫使复制到bin文件夹(我需要这个,因为.dll文件是不是在目标环境)?我可以为文件bin文件夹添加组件,它会工作,但在这种情况下bin文件夹中的内容将在源代码控制,这是不好的。

Why such a behaviour? Is it possible to force copy to bin folder (I need this since .dll is not on target environment)? I can add assembly to bin folder as file and it will work, but in this case bin folder contents will be in source control, which is not good.

推荐答案

您可以设定在参考的复制本地属性设置为True。这应该将其添加到bin文件夹 - 在Web应用程序项目

You can set the Copy Local property to True on the reference. That should add it to the bin folder - on a Web Application project.

但是,对于一个网站项目,当您添加一个参考,它是所有添加一行引用大会web.config中。它会查找该文件第一次在bin文件夹,然后在GAC如果没有找到它。

But for a Web Site project, when you add a reference, all it does is add a line to the web.config that references the assembly. It will look for this file first in the bin folder, and then in the GAC if it is not found.

您有两种选择:要求组件安装在GAC在目标机器上(在这种情况下,XCOPY部署是不可能的),或者包括所有必需的组件在bin文件夹,可通过复制它们,或者写一个生成后脚本这样做。您可以找到使用命令提示符,并打算到c该.dll:\\ WINDOWS \\装配\\ GAC,找到你感兴趣的,cd到该目录,然后cd进入你感兴趣的版本目录中的组装此。会给你在生成后的脚本中使用的路径。例如,对于辅助装配在GAC中,你会落得这样的路径:
C:\\ WINDOWS \\装配\\ GAC \\辅助\\ 1.0.5000.0__b03f5f7f11d50a3a \\ Accessibility.dll

You have two options: require the assembly to be installed in the GAC on the target machine (in which case, XCOPY deployment is not possible) or include all required assemblies in the bin folder, either by copying them in or writing a post-build script that does so. You can find the .dll by using the command prompt and going to c:\windows\assembly\GAC, find the assembly you are interested in, cd into that directory and then cd into the directory with the version you are interested in. This will give you the path to use in your post-build script. For example, for the Accessibility assembly in the GAC, you'd end up with this path: c:\Windows\assembly\GAC\Accessibility\1.0.5000.0__b03f5f7f11d50a3a\Accessibility.dll

您说的,包括源代码控制bin文件夹中的内容并不好。这被普遍认为是真心对你建立二进制文件,但在你的情况,你有没有编译为您的项目的一部分二进制资产。从哲学,这些都等同于图片:二进制资产不编译为您的项目的一部分。我认为他们的源代码控制属于不亚于任何其他二进制项目依托。但它是一个个人的选择。

You say including the bin folder contents in source control is not good. This is generally regarded as true for binaries you build, but in your case, you have binary assets that are not compiled as part of your project. Philosophically, these are equivalent to images: binary assets not compiled as part of your project. I would argue they belong in source control as much as any other binary your project relies on. But it is a personal choice.

这篇关于为什么从海关总署,ASP.NET网站引用程序集添加本地引用时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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