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=, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

In my another project file I've seen that System.Data.Entity was referenced else:

<Reference Include="System.Data.Entity" >

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:

        <!--add assembly references needed for MvcBuildViews build task-->
            <add assembly="System.Data.Entity, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

If there exists a syntax which does not require to specify the full version 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.

Need Your Help

How do I add a variable to a sqlalchemy query filter and convert it to a string query?

python pandas flask sqlalchemy

I have a summarized query that I am trying to put into a pandas data frame in a Flask app. I have figured out how to convert the sqlalchemy query into a string query that pandas can read into a dat...

How to only pass certain form values

javascript html

I have a form which has a lot of SELECTs. For various reasons, I'd like to only pass to the form the ones that are selected by the user. In other words, each SELECT is something like this: