问题
How can I resolve these errors:
- Loading the include file 'EF.Utility.CS.ttinclude' returned a null or empty string.
- Value does not fall within the expected range.
Tools Used: VS 2012, Entity Framework 5.0.0, T4MVCExtensions 3.5.0, .NET Framework 4.5
I've been using EF and T4 templates in a project within a large MVC solution without incident. Now, when I right-click on the edmx diagram, EF responds with the message: Value does not fall within the expected range. When I compile the EF project it responds with these messages:
- Loading the include file 'EF.Utility.CS.ttinclude' returned a null or empty string. The transformation will not be run. C:\Projects\NSAForms\NSAForms\NSAFormsEDM\NSAFormsEntities.tt
- Failed to resolve include text for file:C:\Projects\NSAForms\NSAForms\NSAFormsEDM\EF.Utility.CS.ttinclude C:\Projects\NSAForms\NSAForms\NSAFormsEDM\NSAFormsEntities.tt
Every table in the database has a primary key. I'm struck by how suddenly this issue appeared. Does anyone have some suggestions how to resolve this issue?
Thanks in advance,
Arnold
回答1:
In VS 2012, the EF.Utility.CS.ttinclude file will only be installed if the Microsoft Web Developer Tools or Microsoft SQL Server Data Tools component is selected.
回答2:
I had very similar issue and I tried with VS2012 and VS2013.
After reinstalling Entity Framework 6 Tools for Visual Studio 2012 http://www.microsoft.com/en-us/download/confirmation.aspx?id=40762 every thing went back to normal.
回答3:
Reinstalling Entity Framework 6 Tools for Visual Studio 2012 http://www.microsoft.com/en-us/download/confirmation.aspx?id=40762 work for me
回答4:
For VS2017, I ended up adding EF6.Utility.CS.ttinclude to model's folder. This resolved my issue with MySql and EF.
File can be found: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes\EF6.Utility.CS.ttinclude
UPDATE To avoid doing the above, removing the entities completely then adding back in fixed the issue.
回答5:
Visual Studio 2017
was getting the same error but only in a test project. after reviewing the test project and the other project successfully referencing that file i found that adding the following to the app.config of the failing project resolved my issue
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<connectionStrings>
回答6:
Had this issue with a recent install of VS2017 Enterprise after already having this functionality working in Professional.
The solution for me was to:
- Open the Visual Studio Installer program and "Modify" my Enterprise installation.
- Select "ASP.NET and web development" under the Web & Cloud section
- Click "Modify" in bottom right
It's probably worth noting that I already had EF6 installed and did not need to re-install it to get this to work.
After completing those steps and firing up Visual Studio, the error went away and I was able to generate my classes successfully. Hope this helps!
回答7:
All of the above solutions did not work for me so I created a new project to see if the problem persists but the error did not occur in the newly created project. I then compared the project with the old backup to check recent changes made and found the problem. I recently had upgraded a package Clarius.TransformOnBuild to more recent version after downgrading the package the error went away.
回答8:
In my case the issue was caused by a bizarre folder name (with %20
instead of spaces). I just made a directory junction to the same folder with spaces instead of %20
and it solved the issue.
Here is the PowerShell command I used to make the junction:
cd "c:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Extensions\Microsoft\"
mklink /j "Entity Framework Tools" "Entity%20Framework%20Tools"
Junction created for Entity Framework Tools <<===>> Entity%20Framework%20Tools
You can then use ls
look at the directory contents, and you should see these two lines (edited for brevity):
Mode LastWriteTime Length Name
---- ------------- ------ ----
...
d----l 2/27/2019 9:57 AM Entity Framework Tools
d----- 2/26/2019 12:24 PM Entity%20Framework%20Tools
...
Under Mode, the l
indicates that it is a "link" (aka junction), and the d
indicates it's a directory. By making a junction instead of renaming the folder, you can be sure that both directory names will always work.
来源:https://stackoverflow.com/questions/14999633/how-can-i-resolve-this-error-loading-the-include-file-ef-utility-cs-ttinclude