Prehistory:
I have a simple ASP.NET MVC3 application. In the project file i've turned on building MVC's views :
<MvcBuildViews>True</MvcBuildViews>
Also I use Entity Framework 4.0. And I've added reference to the System.Data.Entity
assembly to my Web project. (Yes, I know this is not good to use data access layer in the UI, it is only for test).
In project file it looks:
<Reference Include="System.Data.Entity" />
Then I've tried to use ObjectContext class in my View (Razor engine), but I've got the error message:
errorCS0012: The type 'System.Data.Objects.ObjectContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
In my another project file I've seen that System.Data.Entity was referenced else:
<Reference Include="System.Data.Entity" >
<Private>True</Private>
</Reference>
Next, I've change project file (reference section) using <Private>True</Private>
child element and the problem has been resolved.
So, What is <Private>True</Private>
and how it affect the build process?
Private=True copies the assembly into the website's "bin" folder where they automatically become part of the website's referenced assembly dictionary.
But you don't want to copy framework assemblies into the bin folder. Just add the following to the web.config which resides in the "~/Views" folder:
<system.web>
<compilation>
<!--add assembly references needed for MvcBuildViews build task-->
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
If there exists a syntax which does not require to specify the full version 4.0.0.0.0 there I would be happy to be informed.