Referencing assemblies in .NET project. Strange behavior
I have a simple ASP.NET MVC3 application. In the project file i've turned on building MVC's views :
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=188.8.131.52, 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=184.108.40.206, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> </assemblies> </compilation>
If there exists a syntax which does not require to specify the full version 220.127.116.11.0 there I would be happy to be informed.
MvcBuildViews is using msbuild to compile your views. It seems that there are some differences between Visual studio and msbuild.
<Private>True</Private> is same to copy local from visual studio.
Actually this solution worked for me
In Solution Explorer, right-click References and select Add Reference from the right-click menu.
The Reference Manager dialog box is displayed.
Select System.Data.Entity from the list in the dialog box if it is not already selected. Make certain the checkbox next to the item is selected.
- Click OK.