向项目不直接使用的程序集添加引用是否正确? [英] Is it correct to add a reference to an assembly that is not directly used by the project?

查看:71
本文介绍了向项目不直接使用的程序集添加引用是否正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由3个项目组成的解决方案。

I have a solution composed by 3 projects.


  • 一个实体框架,其中包含我的edmx图

  • 一个用于我的核心业务

  • 一个用于我的网络应用

  • one for Entity framework that contains my edmx diagram
  • one for my core business
  • and one for my web app

当我在服务器或托管服务上发布代码时,出现此运行时错误:

When I publish my code on a server or hosting service I get this runtime error:

{无法加载文件或程序集'EntityFramework,Version = 4.4.0.0,
Culture = neutral,PublicKeyToken = b77a5c561934e089'或其
依赖项之一。系统找不到指定的文件
。: EntityFramework,Version = 4.4.0.0,Culture = neutral,
PublicKeyToken = b77a5c561934e089}

{"Could not load file or assembly 'EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.":"EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"}

我收到此错误,因为未发布我的实体框架程序集。我的服务器上缺少实体框架dll文件。我知道为什么。我没有在网络应用程序项目中引用它,因为该项目不需要此程序集。我的另两个项目中引用了该程序集。

I get this error because my entity framework assemblies is not published. The entity framework dll file is missing on my server. I know why. I didn't referenced it in my web app project because this assemblies is not required in this project. The assembly is referenced in my two other projects.

我可以通过在Web应用程序中添加实体框架引用来轻松解决问题。我可以那样做吗?是的,但是添加对项目不直接使用的程序集的引用是一种很好的编程方法吗?我该怎么办?

I can easily fix my issue by adding the entity framework reference in my web app. Can I do that? yes but is it good programming to add a reference to an assembly that is not directly used by the project? What can I do?


  • 一个用于实体框架:参考实体框架

  • 一个用于我的核心业务:参考实体框架,因为我操纵我的实体

  • 和我的网络应用的实体:网站就像UI和核心业务之间的立面。我没有在这里引用或使用实体框架。

  • one for Entity framework: reference Entity Framework
  • one for my core business: reference Entity Framework because I manipulate my entities here
  • and one for my web app: web site that act like facade between the UI and the core business. I don't reference or use Entity Framework here.

我没有任何编译错误>我只有一个运行时错误,因为我的实体框架尚未发布。

I don't have any compilation error> I only have a runtime error because my entity framework is not published.

在这种情况下,在Windows应用程序中,我没有引用我的dll,但会通过后期构建操作将其复制。对于要发布或部署的Web应用程序,我不知道该怎么办。

In Windows Application in this case I don't reference my dll in the project but I copy it with a post build action. I don't know what to do in the case of a web app I need to publish or deploy.

推荐答案

您的问题是据我了解,间接引用的程序集不会复制到输出目录中。因此,我认为最好的方法是在Web和Windows项目中也添加对 EntityFramework 的引用。

Your problem is as far as I understand that assemblies referenced indirectly do not get copied to the output directory. So I believe the best way is to add a reference to EntityFramework also to both your web and windows projects.

检查以下答案:将间接引用的程序集复制到输出目录-程序集丢失


引用不会自动级联,因此添加对
OLAF的引用。Tools也不添加对SQLXML的引用。如果要
与exe一起部署SQLXML,那么执行
的最方便方法是从您的exe中显式添加对SQLXML的引用,并将其设置为
以复制本地。没有这个,它就不会部署。

References are not automatically cascaded, so adding a reference to OLAF.Tools does not also add a reference to SQLXML. If you want to deploy SQLXML with your exe, then the most convenient way to do that is to explicitly add a reference to SQLXML from your exe, and set it to copy local. Without this, it is not deployed.

这篇关于向项目不直接使用的程序集添加引用是否正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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