问题
I have a solution composed by 3 projects.
- 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:
{"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"}
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.
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?
More information
- 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.
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.
回答1:
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.
Check this answer: Copying indirectly referenced assembly to output directory - assembly is missing
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.
来源:https://stackoverflow.com/questions/25851984/is-it-correct-to-add-a-reference-to-an-assembly-that-is-not-directly-used-by-the