Visual Studio 2012 - Can't move EF .tt files

entity-framework visual-studio-2012

Question

I noticed in VS2012 that when you make a new EF Model (.edmx) that the DbContext is the default code generation and the .tt (T4 template) files are now nested underneath the .edmx file in the Solution Explorer.

Question: Is there a way to move these .tt files to another folder or project? When I try to drag and drop in Solution Explorer, it won't allow me to move the nested .tt file.

Problem details: Previously (in VS2010) I used to move the one .tt file for my POCOs into a class library called DataDefinitions and I left the other .tt file for my context in a class library called DataAccess. Now it seems like I won't be able to move these files... and separate out my assets into different layers.

In this MSDN article, if you scroll to the bottom, you can see a picture of how the .tt files are now nested... http://msdn.microsoft.com/en-us/data/jj613116

1
14
8/30/2012 3:34:37 PM

Accepted Answer

It is some strange new feature where templates are added as dependency to EDMX file. You can fix it by editing .csproj file for your project (you can do it in notepad or unload project in VS and edit it). You will find something like this:

<None Include="Model.tt">
  <Generator>TextTemplatingFileGenerator</Generator>
  <DependentUpon>Model.edmx</DependentUpon>
  <LastGenOutput>Model.cs</LastGenOutput>
</None>

You just need to remove DependentUpon element and the template item will become independent part of the project.

24
8/30/2012 8:23:06 PM

Popular Answer

I'm using EF5.x a DBContext in a separate project to the EF data model. Despite removing the DependentUpon entry in the project file as stated by Ladislav and here the classes were still appearing under my Model1.tt file.

To get round this, I had to also remove part of the entries from the project file for each of the tables:

<Compile Include="MyTableName.cs">
  <DependentUpon>Model1.tt</DependentUpon>
</Compile>

Only lines with the <DependentUpon> tags should be removed whilst the <Compile Include="..."> tags should be kept. Removing the whole entry will cause the file to disappear from the project list. The entries can be shortened to <Compile Include="MyTableName.cs"\> for brevity.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow